• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate hibernate.cfg.xml from Annotations

 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to generate the mapping elements of hibernate.cfg.xml from the annotated classes? I could probably write something, but I don't believe I'm the first person to think of this.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Strayer wrote:Is there a way to generate the mapping elements of hibernate.cfg.xml from the annotated classes? I could probably write something, but I don't believe I'm the first person to think of this.


Um, they would be unrelated. What can you get from the annotated class that goes into the hibernate.cfg.xml

The hibernate.cfg.xml is for SessionFactory and Hibernate configuration like show_sql and also to say that you are going to use a second level cache.

In the Annotated classes are specific to the class like its mapping to the database and named queries, nothing about the configuration of Hibernate or a SessionFactory.

Mark
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:
Jon Strayer wrote:Is there a way to generate the mapping elements of hibernate.cfg.xml from the annotated classes? I could probably write something, but I don't believe I'm the first person to think of this.


Um, they would be unrelated. What can you get from the annotated class that goes into the hibernate.cfg.xml

The hibernate.cfg.xml is for SessionFactory and Hibernate configuration like show_sql and also to say that you are going to use a second level cache.

In the Annotated classes are specific to the class like its mapping to the database and named queries, nothing about the configuration of Hibernate or a SessionFactory.

Mark


The mapping elements contain the class names. The classes with the hibernate annotations would be the ones that go in the mapping elements.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic