openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eddie Man (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-348) Composite PK with association
Date Thu, 06 Sep 2007 07:44:31 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12525357
] 

Eddie Man commented on OPENJPA-348:
-----------------------------------

Problem solved after I run the enhancer.

It is mean the composite pk with association will not work without enhancement?

> 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({@JoinColumn(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").createEntityManager();
> 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.loadPersistentTypes(AbstractBrokerFactory.java:303)
> 	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:197)
> 	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
> 	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
> 	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
> 	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
> 	at Test.main(Test.java:10)
> Caused by: java.lang.NullPointerException
> 	at org.apache.openjpa.enhance.ManagedClassSubclasser.setDetachedState(ManagedClassSubclasser.java:275)
> 	at org.apache.openjpa.enhance.ManagedClassSubclasser.configureMetaData(ManagedClassSubclasser.java:213)
> 	at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:137)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(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.


Mime
View raw message