openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@terra.com.br
Subject Re: Mapping more than one @ManyToOne relation doesn’t work
Date Tue, 15 Jun 2010 05:26:03 GMT
Hi,

Here is the persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
       <persistence-unit name="project">

               <description>project</description>
               <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>

               <class>persistence.db.dao.Project</class>
               <class>persistence.db.dao.Developer</class>
               <class>persistence.db.dao.Participation</class>

               <properties>
                       <property name="openjpa.jdbc.DBDictionary" value="postgres" />
                       <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"
/>
                       <property name="openjpa.ConnectionDriverName"
value="org.postgresql.Driver" />
                       <property name="openjpa.ConnectionURL"
value="jdbc:postgresql://localhost:5432/project" />
                       <property name="openjpa.ConnectionUserName" value="[user]" />
                       <property name="openjpa.ConnectionPassword" value="[psswd]" />
                       <property name="openjpa.Log" value="SQL=TRACE" />
               </properties>

       </persistence-unit>
</persistence>


Here is the output of the java -jar /path/to/openjpa.jar:

Apache svn revision: 422266:935683

os.name: Mac OS X
os.version: 10.6.3
os.arch: x86_64

java.version: 1.6.0_20
java.vendor: Apple Inc.

java.class.path:
       openjpa-all-2.0.0.jar


And here is the SQL trace I get:

7775  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
1129698211> executing stmnt 630883350 CREATE TABLE Developer (id
BIGINT NOT NULL, connected BOOL NOT NULL, name VARCHAR(200) NOT NULL,
version ABSTIME, PRIMARY KEY (id))
7884  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
1129698211> [109 ms] spent
8175  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
165054145> executing stmnt 2112994712 CREATE TABLE
OPENJPA_SEQUENCE_TABLE (ID SMALLINT NOT NULL, SEQUENCE_VALUE BIGINT,
PRIMARY KEY (ID))
8254  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
165054145> [79 ms] spent
8560  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
885516455> executing stmnt 337501626 CREATE TABLE Participation (id
BIGINT NOT NULL, version ABSTIME, PROJECT_ID BIGINT, PRIMARY KEY (id))
8707  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
885516455> [147 ms] spent
9025  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
621221153> executing stmnt 1836265170 CREATE TABLE Project (id BIGINT
NOT NULL, name VARCHAR(200) NOT NULL, version ABSTIME, PRIMARY KEY
(id))
9117  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
621221153> [92 ms] spent
9492  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
1002735346> executing stmnt 887699865 ALTER TABLE Participation ADD
FOREIGN KEY (PROJECT_ID) REFERENCES Project (id) DEFERRABLE
9581  project  TRACE  [main] openjpa.jdbc.SQL - <t 1902059420, conn
1002735346> [88 ms] spent


As you can see, it doesn't create a column for DEVELOPER_ID.

Any help will be greatly appreciated.

Lile


On Seg 14/06/10 15:43 , lile@terra.com.br sent:
> Hi,
> 
> 
> 
> I’m trying to build my first application using OpenJPA, but I got stuck
> with an odd problem. 
> 
> 
> When declare more than one @ManyToOne relation on one entity, only one
> (sometimes none) of them is mapped correctly on the database. I’ve tried
> with existing tables and creating the tables by 
> running the program, but the behavior doesn’t change.
> 
> 
> 
> Here is the example I’m trying:
> 
> 
> 
> @Entity
> 
> public class Project implements Serializable{
> 
> 
> 
> /**
> 
> * 
> 
> */
> 
> private static final long serialVersionUID = 1L;
> 
> 
> 
> @Id
> 
> @GeneratedValue(strategy = GenerationType.TABLE)
> 
> private long id;
> 
> 
> 
> @Column(nullable = false, length=200)
> 
> private String name;
> 
> ...
> 
> }
> 
> 
> 
> @Entity
> 
> public class Developer implements Serializable{
> 
> 
> 
> /**
> 
> * 
> 
> */
> 
> private static final long serialVersionUID = -3366659313976911445L;
> 
> 
> 
> @Id
> 
> @GeneratedValue(strategy = GenerationType.TABLE)
> 
> protected long id;
> 
> 
> 
> @Column(nullable = false, length = 200)
> 
> private String name;
> 
> ...
> 
> }
> 
> 
> 
> @Entity
> 
> public class Participation implements Serializable {
> 
> 
> 
> /**
> 
> * 
> 
> */
> 
> private static final long serialVersionUID = -5739921124942905231L;
> 
> 
> 
> @Id
> 
> @GeneratedValue(strategy = GenerationType.TABLE)
> 
> protected long id;
> 
> 
> 
> @ManyToOne(cascade = CascadeType.ALL)
> 
> @ForeignKey
> 
> private Project project;
> 
> 
> 
> @ManyToOne(cascade = CascadeType.ALL)
> 
> @ForeignKey
> 
> private Developer developer;
> 
> ...
> 
> }
> 
> 
> 
> 
> 
> In Participation either a column referring to Project or one referring to
> Developer is created. If I add another @ManyToOne relation, I still get
> only the mapping of one column correctly.
> 
> 
> I’m using PosgreSQL.
> 
> 
> 
> Any ideas of what is happening? 
> 
> Help me, please.
> 
> 
> 
> Lile
> 
> 
> 
> 
> 


Mime
View raw message