Hello list,

I'm new in O/R mapping world, and I have a problem regarding the modeling of
certain entities.

I realize an application that allows to use data from performance
benchmarks.

Elements used :
- OpenJpa 1.2.1 ;
- Java Jdk 1.6 ;
- Postgresql 8.3 ;
- Postgresql JDBC driver v8.3-603.jdbc4.

On a 'machine', an 'instance' is polled with a 'probe' ; the
'probedinstance' provides a 'source' of data.

You can look at the attached database schema.

My problem is focused on the link between the entity 'probedinstance' and
'source'.
'probedinstance' to 'source' --> OneToMany
'source' to 'probedinstance' --> ManyToOne

'probedinstance' has a composed key made with 'id_instance' and 'id_probe'.

When a 'source' is inserted in the database by OpenJpa, an exception is
thrown because of a foreign key violation.

1958  App  TRACE  [main] openjpa.jdbc.SQL - <t 21860890, conn 18452466>
executing prepstmnt 17240206 INSERT INTO ProbedInstance (id_instance,
id_probe) VALUES (?, ?) [params=(int) 21, (int) 21]
1958  App  TRACE  [main] openjpa.jdbc.SQL - <t 21860890, conn 18452466> [0
ms] spent
...
Caused by: <openjpa-1.2.1-r752877:753278 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: ERROR: insert or update
on table "source" violates foreign key constraint "fk_probedinstance_source"
  Détail : Key (id_instance,id_probe)=(0,0) is not present in table
"probedinstance". {prepstmnt 13623369 INSERT INTO Source (name_source,
id_probe, id_instance) VALUES (?, ?, ?) [params=(String)
java.lang:type=OperatingSystem, (int) 0, (int) 0]} [code=0, state=23503]


The 'probedinstance' is well inserted, but after, when the source is
inserted, the foreign key for the 'probedinstance' is (0, 0),
then it must be (21, 21).

It's a mapping problem, but I can't see it.
I read a lot of documentation, as well as the example (Magazine), but I
can't make the connection with what I have to do.

I attached :
- the database schema ;
- Java class and persistence.xml (the main app to test is App.java) ;
- the stack trace, with SQL trace.

Could someone help me to make the right mapping between this entities.

Best regards
http://n2.nabble.com/file/n3147769/traces.zip traces.zip 
-- 
View this message in context: 
http://n2.nabble.com/-newbe--Mapping-problem-between-entities--%3E-foreign-key-violation-tp3147769p3147769.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to