The persistent fields including the identity fields are all declared
public and being accessed/mutated publicly by the test class.
Firstly, public-ness of persistent field is not a good practice.
Secondly, if a class X is not persistent by itself but directly
manipulating public fields of a Entity class Y, then X is termed as
Persistent-Aware. Persistent-Aware classes need no special annotation
but requires to be enhanced. 
In this case, Test class is persistence-aware and most likely has not
been enhanced.



Pinaki Poddar
972.834.2865
 

>-----Original Message-----
>From: Eddie Man (JIRA) [mailto:[EMAIL PROTECTED] 
>Sent: Tuesday, September 04, 2007 1:57 AM
>To: [email protected]
>Subject: [jira] Created: (OPENJPA-348) Composite PK with association
>
>Composite PK with association
>-----------------------------
>
>                 Key: OPENJPA-348
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-348
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.0.0
>            Reporter: Eddie Man
>
>
>I got an exception while using a association within a composite PK
>
>A.java
>========
>@Entity
>public class A {
>       @Id
>       public int id;
>       
>       @OneToMany(mappedBy="a", cascade=CascadeType.ALL)
>       public HashSet<B> bs = new HashSet<B>();
>
>}
>
>B.java
>========
>@Entity
>@IdClass(BPK.class)
>public class B {
>       
>       @Id
>       public int id;
>       
>       @Id
>       @ManyToOne(cascade=CascadeType.ALL)
>       @JoinColumns([EMAIL PROTECTED](name="aid")})
>       public A a;
>       
>       @Basic
>       public String name;
>}
>
>BPK.class
>============
>public class BPK {
>       
>       public int id;
>       
>       public int a;
>
>       @Override
>       public boolean equals(Object aObj) {
>               return super.equals(aObj);
>       }
>       
>       @Override
>       public int hashCode() {
>               return super.hashCode();
>       }
>}
>
>
>Here is my code for inserting data to db:
>EntityManager manager = 
>Persistence.createEntityManagerFactory("openjpa").createEntityM
>anager();
>EntityTransaction transaction = manager.getTransaction(); 
>transaction.begin();
>               
>A a = new A();
>a.id = 1;
>               
>B b = new B();
>b.id = 2;
>b.a = a;               
>               
>a.bs.add(b);
>               
>manager.persist(a);
>transaction.commit();
>manager.close();
>
>Exception :
>==============
>Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal 
>general error> 
>org.apache.openjpa.persistence.PersistenceException: null
>       at 
>org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentT
>ypes(AbstractBrokerFactory.java:303)
>       at 
>org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(Abstr
>actBrokerFactory.java:197)
>       at 
>org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(Del
>egatingBrokerFactory.java:142)
>       at 
>org.apache.openjpa.persistence.EntityManagerFactoryImpl.createE
>ntityManager(EntityManagerFactoryImpl.java:192)
>       at 
>org.apache.openjpa.persistence.EntityManagerFactoryImpl.createE
>ntityManager(EntityManagerFactoryImpl.java:145)
>       at 
>org.apache.openjpa.persistence.EntityManagerFactoryImpl.createE
>ntityManager(EntityManagerFactoryImpl.java:56)
>       at Test.main(Test.java:10)
>Caused by: java.lang.NullPointerException
>       at 
>org.apache.openjpa.enhance.ManagedClassSubclasser.setDetachedSt
>ate(ManagedClassSubclasser.java:275)
>       at 
>org.apache.openjpa.enhance.ManagedClassSubclasser.configureMeta
>Data(ManagedClassSubclasser.java:213)
>       at 
>org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenha
>ncedClasses(ManagedClassSubclasser.java:137)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccesso
>rImpl.java:39)
>       at 
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMetho
>dAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at 
>org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentT
>ypes(AbstractBrokerFactory.java:287)
>       ... 6 more
>
>--
>This message is automatically generated by JIRA.
>-
>You can reply to this email to add a comment to the issue online.
>
>

Notice:  This email message, together with any attachments, may contain 
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated 
entities,  that may be confidential,  proprietary,  copyrighted  and/or legally 
privileged, and is intended solely for the use of the individual or entity 
named in this message. If you are not the intended recipient, and have received 
this message in error, please immediately return this by email and then delete 
it.

Reply via email to