Forums Register Login

Qualified OneToMany-ManyToOne relation

+Pie Number of slices to send: Send
Hi, i try to build a sample qualified relation and get an error.









Anyone an idea what is wrong here?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Come on, let's reason together. And see what we can learn.

Can you post the code entirely for 2 classes: Bike and Tire?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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)?
+Pie Number of slices to send: Send
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
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5392 times.
Similar Threads
Deleted records while merging
Problem with OneToMany bidirectional
bidirectional ManyToMany with java.util.Map
No mapped data?
Entity object not getting persisted: new object was found through a relationship that was not marked
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:33:34.