Hi Craig/Patrick,
Thanks for your guidance. I did try the options given by you
people. In fact, as Craig pointed out I had a identity property in the
bean, which I never used it. After I removed it, I got a different
exception. As Patrick suggested, I have moved the InnerProduct as a
top-level class. I got the same exception in both the cases.
The stack trace is below
2547 firstcall WARN [main] openjpa.Enhance - [Possible violation of
subclassing contract detected while processing persistent field
com.ibm.retail.Product$InnerProduct.innerDesc, declared in
C:\projectworkspaces\PoT\OpenJPAPoT\META-INF\mapping.xml. Are you sure you
are obeying the OpenJPA requirements? Details: The getter for field
innerDesc does not obey OpenJPAs subclassing restrictions. Getters must
return a single non-computed field., Possible violation of subclassing
contract detected while processing persistent field
com.ibm.retail.Product$InnerProduct.innerDesc, declared in
C:\projectworkspaces\PoT\OpenJPAPoT\META-INF\mapping.xml. Are you sure you
are obeying the OpenJPA requirements? Details: The setter for field
innerDesc does not obey OpenJPAs subclassing restrictions. Setters must
assign the passed-in parameter to a single field in the object., Possible
violation of subclassing contract detected while processing persistent
field com.ibm.retail.Product$InnerProduct.innerName, declared in
C:\projectworkspaces\PoT\OpenJPAPoT\META-INF\mapping.xml. Are you sure you
are obeying the OpenJPA requirements? Details: The getter for field
innerName does not obey OpenJPAs subclassing restrictions. Getters must
return a single non-computed field., Possible violation of subclassing
contract detected while processing persistent field
com.ibm.retail.Product$InnerProduct.innerName, declared in
C:\projectworkspaces\PoT\OpenJPAPoT\META-INF\mapping.xml. Are you sure you
are obeying the OpenJPA requirements? Details: The setter for field
innerName does not obey OpenJPAs subclassing restrictions. Setters must
assign the passed-in parameter to a single field in the object.]
Exception in thread "main" <openjpa-1.1.0-r422266:657916 nonfatal general
error> org.apache.openjpa.persistence.PersistenceException: An error
occurred while enhancing com.ibm.retail.Product$InnerProduct. Exception
message: null
at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:538)
at
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(
ManagedClassSubclasser.java:144)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(
AbstractBrokerFactory.java:310)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(
AbstractBrokerFactory.java:228)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(
AbstractBrokerFactory.java:190)
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 com.ibm.persistence.OpenJPAPersister.main(
OpenJPAPersister.java:13)
Caused by: java.lang.NullPointerException
at org.apache.openjpa.enhance.PCEnhancer.addAttributeTranslation(
PCEnhancer.java:707)
at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:514)
... 9 more
I am providing the code snippet as well as the mapping.xml files.
------------------------------------Code
Snippet---------------------------------
package com.ibm.retail;
import java.io.Serializable;
public class Product implements Serializable {
private String name;
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static class InnerProduct implements Serializable{
Product product = new Product();
public String getInnerDesc() {
return product.getDescription();
}
public void setInnerDesc(String innerDesc) {
product.setDescription(innerDesc);
}
public String getInnerName() {
return product.getName();
}
public void setInnerName(String innerName) {
product.setName(innerName);
}
}
}
-------------------Mapping.xml---------------------
<entity class="com.ibm.retail.Product">
<table name="PRODUCT"/>
<attributes>
<basic name="name">
<column name="NAME"/>
</basic>
<basic name="description">
<column name="DESCRIPTION"/>
</basic>
</attributes>
</entity>
<entity class="com.ibm.retail.Product$InnerProduct" access=
"PROPERTY">
<table name="PRODUCT"/>
<attributes>
<basic name="innerName">
<column name="NAME"/>
</basic>
<basic name="innerDesc">
<column name="DESCRIPTION"/>
</basic>
</attributes>
</entity>
-------------------------
Hi Arun,
Do you have any identity property in your beans? The missing identity
property might be disguised as wrong default for the other persistent
properties.
And what Patrick says...
Craig
On Jun 25, 2008, at 10:32 AM, Arun Nagarajan wrote:
> Hi,
> I have a set of java classes which has only setter and getter
> methods (as they are generated using XML beans). At the entity
> level, I
> have defined the access as 'PROPERTY'. But when I try to persist
> them, I
> am getting the following error. Can you please let me know how to
> persist
> java classes, which have only getter and setter methods.
>
> Fields "com.ibm.retail.Product$InnerProduct.innerDesc,
> com.ibm.retail.Product$InnerProduct.innerName" are not a default
> persistent type, and do not have any annotations indicating their
> persistence strategy. If you do not want these fields to be
> persisted,
> annotate them with @Transient.
>
> The mapping.xml reads like this. The InnerProduct class has
> getInnerName
> and getInnerDesc as well as setInnerName and setInnerDesc methods. No
> fields.
>
> <entity class="com.ibm.retail.Product$InnerProduct" access="PROPERTY">
> <table name="PRODUCT"/>
> <attributes>
> <basic name="InnerName">
> <column name="NAME"/>
> </basic>
> <basic name="InnerDesc">
> <column name="DESCRIPTION"/>
> </basic>
> </attributes>
> </entity>
>
> Thanks and Regards,
> arun...
>
------------------------------------------------------------------------------------------------------------------------
> Arun N,
> IBM
>
------------------------------------------------------------------------------------------------------------------------
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!
Thanks and Regards,
arun...
------------------------------------------------------------------------------------------
Arun Nagarajan,
IBM
------------------------------------------------------------------------------------------