• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA Mapping Exception

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

I have a simple JPA mapping to a couple of tables via the XML config file. However, during startup, I get the following errors:



Below is how my mapping looks like: A Question has many Answers:


What is the mistake here?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Modified the definitions like below:



And following is the exception:

 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously no reason why Annotation mapping makes life easier.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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
and

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

How does the datamodel look like?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The data model is quite simple. A Question has many Answers and it is a simple One-To-Many bidirectional relationship.

In my first post above, I had the Ont-To-Many definition outside of the id attribute and it did not work either.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems like I have to change to Annotation mapping as this is not moving any further with my development.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Tamas Polgar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Answer:

xml for it:

Question

xml:

sql script:

It works for me, with hibernate as well.
Note:
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.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the post. It deploys fine now.
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic