This is a list of Java Persistence API annotations and things that are supported so far.
Details
- @ManyToOne - object references. Stores id reference to another object in another Domain
- @OneToMany (java.util.List only, must be generified, must be bi-directional with mappedBy parameter) - Collection support. Please be careful with collections, usually better to just query for what you want rather than attaching via collections.
- @Inheritance - Only SINGLE_TABLE supported (only one that makes sense).
- @MappedSuperClass - Useful for a common ID and timestamping class.
- @Lob - stores lobs in S3 so make it as big as you want (up to 5GB).
- @Id - MUST be a string
- JPA Queries - see JPAQuery page
- Integer and Long - no problems, all good.
- Double - pads to 20 digits on each side of the decimal by default so fine for a lot of cases, but if you plan to use Double's, let us know so we can work it out perfectly. SimpleDB makes it hard to work with these numbers because it treats everything as a String.
- BigDecimal - same problems as Double
- String
- no primitives yet! Please use wrappers only for now.
- @Enumerated (ordinal and string)
- @Column (name only)
- @EntityListeners - for lifecycle callbacks.
- @Transient - won't persist these fields.
If you want doubles to be sorted correctly, it can be done, but they need to be specially encoded. You operate on the IEEE floating point bit level, flipping certain bits based on the sign.
Now store the bits as a padded, unsigned hexadecimal String, 16 characters in length. To decode from the bits:
This is the same trick used by Carbonado and BerkeleyDB's DPL.
Thanks a lot bronee! I'll have to give that a try.
Is there a directive to tell the framework to ignore a attribute and not persist it?
Use the @Transient annotation to have SimpleJPA ignore it.
Has anyone tried SimpleJPA with Grails? This article, "http://blogs.sun.com/enterprisetechtips/entry/combining_groovy_grails_mysql_and" talks about using JPA with Java domain objects instead of Grails domain objects. Since this example seems simple enough, it should work with Amazon SimpleDB and SimpleJPA.
If I get to try it out I will let you know.
How about transactions? Are they fully supported? Including operations on several entity types during 1 transaction?
If you want to make a OneToOne? relation the following code does the trick: @OneToOne? @Column(name="class_id")
Where class is the name of the class being related to this entity. For example, if it's the class User:
@OneToOne? @Column(name="user_id")
Regards.
How to I enable @OneToMany? relationship?
EntityManager? em = getEntityManager();
this does not store the domains.