This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
using hibernate as jpa2 provider could produce wierd situations
For your first problem:
If you change the order of your attribute mappings in Answer, and put <many-to-one name="question"/> to the last statement, it should pass the XMLSchemaValidation. It shouldnt be a problem with a jpa2 provider, but with hibernate, it is.
You use <one-to-many name="answers" mapped-by="answerId"> in your Question, this should be mapped by an attribute with Question type, with many-to-one relation type.
For your second problem
are not good, you cannot use one-to-many or many-to-one in the id tag.
Try to put them outside the id, and sculp it a bit
Tried to get rid of all the mapping errors. But now getting an all together new exception....
Where Technology is an Entity as defined below:
Are sequences not supported in MySQL database?
Joined: Apr 27, 2011
There are no sequences in mysql,
you can use id generation (when you insert the record, it generates an id, dont use it for complex relationships), or table generator which is quite cool (details).
so I created a simple version of your stuff
xml for it:
It works for me, with hibernate as well.
many-to-one and one-to-many are the last elements of the mappings. with hibernate it seems to be required..
You dont need to use basic if you use default values (other attribute = other column). Try to use default values, it can reduce the code, and improves the readability.
you can use annotation or xml, or both. you can specify the same mapping with xml and annotations (in theory ).
however annotations could be easier to understand how jpa works.