• 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

Qualified OneToMany-ManyToOne relation

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i try to build a sample qualified relation and get an error.









Anyone an idea what is wrong here?
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have some some settings (for example using hibernate)



to see all the DDL/Create Table statements and the DML/Insert statements
to see which Insert statment that cause the exception and go from there.
 
Toni Black
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, i should have posted it right at the beginning. But i was shure it is a very prevalent mistake The problem is that the column that should not be null is not inserted at all (visible in the second listing).

DDL create statments

and the insert statement

Anyone an idea?
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Come on, let's reason together. And see what we can learn.

Can you post the code entirely for 2 classes: Bike and Tire?
 
Toni Black
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you can see i tried different approaches (commented in Tire and Bike) but always with the same result of no value for the TIRE_POSITION column.


And for the total completeness the test class.
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I depends 2 things:

DEBUGGER + DOC HIBERNATE - Relational Persistence for Idiomatic Java VERSION 4.3.6.Final
http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/

7.2.2.2. Maps
Example 7.10. Use of target entity property as map key via @MapKey
Example 7.11. Map key as basic type using @MapKeyColumn


Most important:
Regardless of which of the above 2 ways,
the main cause of problem is that your Tire class is missing a critical piece of information:


Now can you adjust your code using below Option 1 or 2. Test and see how it is.
Do not forget to use the mentioned Hibernate documentation.


 
Toni Black
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i tried both suggestions and this are the results.

The test itself is the same for both options.


OPTION 1
-> PROBLEM : Still have null inserts for the key values.



BTW i tried to use the Hibernate instead of eclipselink with the following result.


OPTION 2
-> PROBLEM : i still have null inserts for the key values + two further columns in the tire table (which should be managed only in the Bike_Tire table)



And the same test with hibernate

Other suggestions?
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For now, stick to the original issue, meaning stick with EclipseLink as your JPA provider.

Did you set the value for Tire position?

Instead of saying it does not work, use a DEBUGGER if you can't read the code and set a break at Map in your MyTest class, then examine
the state of tireFront and tireBack objects.
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Toni,

1. For reference see my post dated posted September 1, 2014 10:34:47 AM PDT

For Option 2, you need this key piece of info: @Column(name="TIRE_POSITION")



2.

While testing using SessionFactory it worked fine without

But with EntityManager, there is an exception.

Internal Exception: java.sql.SQLIntegrityConstraintViolationException: cannot insert NULL into 'TIRE_POSITION'  

To fix this, you need @Column(name="TIRE_POSITION")

3. Given you're using EntityManager, you need to copy the above code in point 1.

4. Should it OK now for your testing.

5. Mine worked perfectly in 2 cases using SessionFactory and EntityManager.
 
Toni Black
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Big thanks for your effort to help me but i still don't get it . Could you post or upload the complete code (or probably the entire test project)?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A quick read through of this and the first question that pops into my head is, what is the actual name of the column in the database?
So far in this thread I've seen:
TIRE POSITION (I don't know if it's a sign of my age or something, but column names with spaces make me itch).
TIRE_POSITION
tirePosition
reply
    Bookmark Topic Watch Topic
  • New Topic