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 Wed, 05 Sep 2007 09:16:35 GMT

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

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

I found that the problem is only occur is the persistence object is default package.

After I move the class to "sss" package, then I get the following exception:

[code]
35  openjpa  INFO   [main] openjpa.Runtime - Starting OpenJPA 1.0.0
331  openjpa  INFO   [main] openjpa.Enhance - Creating subclass and redefining methods for
"[class sss.B, class sss.A]". This means that your application will be less efficient than
it would if you ran the OpenJPA enhancer.
662  openjpa  TRACE  [main] openjpa.Enhance - Enhancing type "class sss.B".
732  openjpa  TRACE  [main] openjpa.Enhance - Enhancing type "class sss.A".
Exception in thread "main" <openjpa-1.0.0-r420667:568756 nonfatal general error> org.apache.openjpa.persistence.PersistenceException:
sss.A cannot be cast to java.lang.Number
	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2402)
	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2298)
	at org.apache.openjpa.kernel.BrokerImpl.persistAll(BrokerImpl.java:2244)
	at org.apache.openjpa.kernel.SingleFieldManager.persist(SingleFieldManager.java:267)
	at org.apache.openjpa.kernel.StateManagerImpl.cascadePersist(StateManagerImpl.java:2840)
	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2397)
	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2216)
	at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1005)
	at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:541)
	at Test.main(Test.java:21)
Caused by: java.lang.ClassCastException: sss.A cannot be cast to java.lang.Number
	at org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.fetchIntField(ApplicationIds.java:537)
	at org.apache.openjpa.enhance.sss$B$pcsubclass.pcCopyKeyFieldsToObjectId(Unknown Source)
	at org.apache.openjpa.enhance.PCRegistry.copyKeyFieldsToObjectId(PCRegistry.java:160)
	at org.apache.openjpa.util.ApplicationIds.fromPKValues(ApplicationIds.java:185)
	at org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcNewObjectIdInstance(ReflectingPersistenceCapable.java:257)
	at org.apache.openjpa.util.ApplicationIds.create(ApplicationIds.java:384)
	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2370)
	... 9 more
[/code]

> 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