Hibernate Annotations FAQ
Here are some Hibernate Annotations related FAQs.
-
Hibernate Annotations FAQ
- I have migrated to a newer version and something went wrong
- I can't EAGER more than one collection !?
- I get an exception when I load more than one collection !?
- I use @org.hibernate.annotations.Entity and get an Unknown entity exception
- I have AnnotationException: No identifier specified for entity
- I'm having NoSuchMethodException(s)
- How to make the reverse engineering tools create an appropriate annotated composite id?
- Where can I see the hbm.xml files generated from the Annotations?
- I have issues with the schema creation with Derby
- @Serialized was working for me, and now that I use @Lob it fails
- How can I set inverse="true"?
- How do I persist my superclass properties?
- My Annotated class will not load
I have migrated to a newer version and something went wrong
Please check the Java Persistence Migration Guide
I can't EAGER more than one collection !?
I get an exception when I load more than one collection !?
Yes you can, here are the solutions:
- do not use a bag semantic: use a Set or a List annotated with @IndexColumn
- use a @CollectionId
- use @FetchMode(SELECT) or @FetchMode(SUBSELECT)
The underlying reason is that you cannot load more than one bag semantic collection in a given SQL query conceptually, so you won't find this feature in other products either.
I use @org.hibernate.annotations.Entity and get an Unknown entity exception
Always import @javax.persistence.Entity
@org.hibernate.annotations.Entity completes @javax.persistence.Entity but is not a replacement
I have AnnotationException: No identifier specified for entity
Set @Id in one of your property or field. Placing it on a field or a method will define the access type strategy
I'm having NoSuchMethodException(s)
Not all Hibernate Annotations versions works with every Hibernate Core version. Be sure to use the appropriate Hibernate core version (and the embedded version of ejb3-persistence.jar).
How to make the reverse engineering tools create an appropriate annotated composite id?
The reverse engineering mechanism from DB to the annotated domain model is currenlty in alpha stage. Composite ids are not yet properly handled.
Where can I see the hbm.xml files generated from the Annotations?
You can't. The annotations are building the internal Hibernate metadata model without any indermediate xml file.
I have issues with the schema creation with Derby
Derby has some limitations that prevent the DDL generation to work properly.
@Serialized was working for me, and now that I use @Lob it fails
Due to a change in the EJB3 specification, @Serialized is gone and has been replaced by a mapping through a blob. Many JDBC drivers have issues with Blob. @Serialized can be replaced by @Type(type="serializable").
How can I set inverse="true"?
The semantic equivalent is mappedBy in the association annotations. Have a look at the reference guide for a complete explaination.
How do I persist my superclass properties?
Annotate your superclass with @MappedSuperclass (This behavior changed compared to earlier implementations of Hibernate Annotations).
My Annotated class will not load
If you did not annotate with javax.persistence.Entity the AnnotationConfiguration class will ignore it. In particular, be sure you did not use org.hibernate.annotation.Entity by mistake. A good test is to use programmatic configuration via AnnotationConfiguration.addAnnotatedClass() rather than a hibernate.cfg.xml entry for the class in question.
Comments