1

Is there any way or any utility to generate hibernate mapping files or directly the database tables from POJOs. I cannot manually insert hibernate annotations since these POJOs are generated dynamically in my application. Please suggest a solution.

3 Answers 3

1

Instead of using annotations you could also use 'old fashioned' .hbm.xml mapping files. This is the classic way of defining a mapping with Hibernate which uses an external xml file to describe the mapping. You could generate the mappings at the same time when you generate your POJOs. Or if the POJO generation is done by external code you could add this yourself.

Once you have a mapping you can use the standard Hibernate facilities to create/upgrade the database schema...

Sign up to request clarification or add additional context in comments.

2 Comments

Actually I am generating POjos from XML schema using jibx. It generates POJOs with a binding.xml while defines the relationship between POJOs and xml schema. So is there a way to generate POJOs and mappings from xml schema at the same time ?/ Thanks for ur suggestion.
I don't have any experience with jibx, but after a quick look at their webpage I did not see a way to do this. It seems like you're out of luck. Maybe you can create your own version of jibx that adds annotations, or allows you also generate a mapping xml file for each class created.
1

Alternatively you could change your code generation in your application to include the javax.persistence annotations.

5 Comments

Thanks for the reply. I am generating these POJOs from XML schema using jibx. How can I make it to include javax.persistence notations in POJOs. Please give a suggestion.
@deep, from the jixb documentation I couldn't find a simple way to do it.
Is other any other way to convert XML schema to POJOs and also generate the corresponding database tables ??
You could for example edit the generated Java files after code generation. I mean make them static and not generated anymore.
I cannot do this manually since every time there will be different java classes generated from different xml schemas.
0

What I do is this:

  1. use a scaffolding application like Grails (ay would do Rails, Sails, etc).
  2. Then reverse Engineer them into pojos via Eclipse

It works everytime and using Grails is fast and VERY easy to use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.