Re: Bug when persisting two related objects
I don't think it matters whether you are using DB2 or any other database. Getting back to one of Patrick's earlier requests... Can you post more information on the Project and Base classes? You've posted a snippet of the Base class and it's ID, but how are you defining the Project and it's ID? As Abe as pointed out, if two classes in an inheritance hierarchy use the same ID class, then unique id values need to be provided for each instance. Could you also post your DDL for generating your tables? Was this hand-generated DDL or created by the OpenJPA tooling? Thanks. Kevin On 5/10/07, Majeed Arni [EMAIL PROTECTED] wrote: I am using DB2 to generate the Identity as in the DDL: ID BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) And in code for the base class: @MappedSuperclass @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Base { . @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = ID) private long someID; .} Will this not use a unique ID generator per derived class? Is there a better way of doing it in DB2? Thanks for the help. Majeed Arni Abe White wrote: Are the two types related by inheritance? If two classes in an inheritance hierarchy use the same id class, then every instance of both classes must have a distinct id value. If you want instances in inheritance-related classes to be able to have the same id values, then you must use different id classes for different classes in the inheritance hierarchy. 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. -- View this message in context: http://www.nabble.com/Bug-when-persisting-two-related-objects-tf3719319.html#a10416417 Sent from the open-jpa-dev mailing list archive at Nabble.com.
Re: How do we know the entity is successfully deployed on appserver
Joshua, Most definitely you can ask user questions on this list. Thanks for posting. OpenJPA provides the ability to autogenerate the database tables at runtime via the SynchronizeMappings property in the persistence.xml. Here's an example usage: persistence-unit name=inheritance classmy.persistence.tests.inheritance.RootEntity/class classmy.persistence.tests.inheritance.LeafEntity/class classmy.persistence.tests.inheritance.AbstractEntity/class properties property name=openjpa.ConnectionDriverName value=org.apache.commons.dbcp.BasicDataSource/ property name=openjpa.ConnectionProperties value=DriverClassName=org.apache.derby.jdbc.EmbeddedDriver ,Url=jdbc:derby:target/temp/play/play.test;create=true,MaxActive=100,MaxWait=1,TestOnBorrow=true/ property name=openjpa.jdbc.SynchronizeMappings value=buildSchema(ForeignKeys=true)/ property name=openjpa.Log value=DefaultLevel=INFO/ /properties /persistence-unit On 5/11/07, Joshua Jackson [EMAIL PROTECTED] wrote: Dear all, How do I know whether an entity is successfully deployed on an appserver? Usually I detect this by autogenerating tables in database. Is there anyway I can autogenerate tables in database with OpenJPA? I've searched in documentation but perhaps I have missed it when reading it. Last but not least, am I allowed to ask user questions in this list? Since this is a dev list. Thanks in advance -- YM!: thejavafreak Blog: http://www.nagasakti.or.id/roller/joshua/
Re: Bug when persisting two related objects
The DDL is handmade. There is nothing in code about Identity. It is done in Database. I found a workaround for this problem by just moving the code around. Looks like a bug is the wrong message it sends. Also, is there a way to generate DDL from Java code? I saw create=true for Derby, does that work for DB2 also? Thanks again. Majeed Kevin Sutter wrote: I don't think it matters whether you are using DB2 or any other database. Getting back to one of Patrick's earlier requests... Can you post more information on the Project and Base classes? You've posted a snippet of the Base class and it's ID, but how are you defining the Project and it's ID? As Abe as pointed out, if two classes in an inheritance hierarchy use the same ID class, then unique id values need to be provided for each instance. Could you also post your DDL for generating your tables? Was this hand-generated DDL or created by the OpenJPA tooling? Thanks. Kevin On 5/10/07, Majeed Arni [EMAIL PROTECTED] wrote: I am using DB2 to generate the Identity as in the DDL: ID BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) And in code for the base class: @MappedSuperclass @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Base { . @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = ID) private long someID; .} Will this not use a unique ID generator per derived class? Is there a better way of doing it in DB2? Thanks for the help. Majeed Arni Abe White wrote: Are the two types related by inheritance? If two classes in an inheritance hierarchy use the same id class, then every instance of both classes must have a distinct id value. If you want instances in inheritance-related classes to be able to have the same id values, then you must use different id classes for different classes in the inheritance hierarchy. 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. -- View this message in context: http://www.nabble.com/Bug-when-persisting-two-related-objects-tf3719319.html#a10416417 Sent from the open-jpa-dev mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Bug-when-persisting-two-related-objects-tf3719319.html#a10432604 Sent from the open-jpa-dev mailing list archive at Nabble.com.
[jira] Commented: (OPENJPA-206) Key column does not cascade multiple joins.
[ https://issues.apache.org/jira/browse/OPENJPA-206?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12495089 ] Michael Dick commented on OPENJPA-206: -- For what it's worth I've been able to reproduce the issue with a vanilla junit test case using the entities provided. i haven't been able to determine why Department is able to pick up the ID from Company, but Employee can't pick up the IDs from Department. I've been able to get it working by persisting Department Company objects in one transaction, then adding the Employees in later. Is that an acceptable workaround for what you're trying to do? Key column does not cascade multiple joins. --- Key: OPENJPA-206 URL: https://issues.apache.org/jira/browse/OPENJPA-206 Project: OpenJPA Issue Type: Bug Affects Versions: 0.9.7 Environment: WebSphere 6.1, DB2 v8.1 Reporter: Matt Anderson Attachments: FunInheritanceJavaPI.zip Problem: Parent keys will not cascade beyond one generation. Example: Company -- Department -- Employee: Company key will not cascade to Employee. The following example further describes this issue. A COMPANY table contains two columns, COMP_ID and NAME. The COMP_ID column is the primary key. A DEPARTMENT table contains three columns, COMP_ID, DEPT_ID, and NAME. The COMP_ID and DEPT_ID columns are the primary key columns. The COMP_ID column is a foreign key column which references the COMP_ID column in the COMPANY table. An EMPLOYEE table contains four columns, COMP_ID, DEPT_ID, EMP_ID, and NAME. The COMP_ID, DEPT_ID, and EMP_ID columns are the primary key columns. The COMP_ID and DEPT_ID columns are foreign key columns which reference the COMP_ID and DEPT_ID columns respectively in the DEPARTMENT table. An entity exists for each table, Company, Department, and Employee. The Company entity has three attributes, compId, name, and departments. The compId attribute maps to the COMP_ID column. The name attribute maps to the NAME column. The departments attribute maps a one-to-many relationship to the Department entity. The Department entity has five attributes, compId, deptId, name, employees, and company. The compId attribute maps to the COMP_ID column. The deptId attribute maps to the DEPT_ID column. The name attribute maps to the NAME column. The employees attribute maps a one-to-many relationship to the Employee entity. The company attribute maps a many-to-one relationship to the Company entity, joined by the COMP_ID column. The Employee entity has five attributes, compId, deptId, empId, name, and department. The compId attribute maps to the COMP_ID column. The deptId attribute maps to the DEPT_ID column. The empId attribute maps to the EMP_ID column. The name attribute maps to the NAME column. The department attribute maps a many-to-one relationship to the Department entity, joined by the COMP_ID and DEPT_ID columns. Below are the eleven steps to re-create this problem. 1. A new Company entity is instantiated. 2. The name attribute on the Company instance is set to company. 3. A new Department entity is instantiated. 4. The name attribute on the Department instance is set to department. 5. The department attribute on the Company instance is set to the Department instance. 6. A new Employee entity is instantiated. 7. The name attribute on the Employee instance is set to Frank. 8. The employee attribute on the Department instance is set to the Employee instance. 9. The Employee instance is added to the employees attribute on the Department instance. 10. The Department instance is added to the departments attribute on the Company instance. 11. The Company instance is persisted. The following SQL statements are executed. INSERT INTO COMPANY (COMP_ID, NAME) VALUES (?, ?) [params=(long) 1, (String) company] INSERT INTO DEPARTMENT (COMP_ID, DEPT_ID, NAME) VALUES (?, ?, ?) [params=(long) 1, (long) 1, (String) department] INSERT INTO EMPLOYEE (DEPT_ID, EMP_ID, NAME) VALUES (?, ?, ?) [params=(long) 1, (long) 1, (String) Frank] A PersistenceException is thrown because of the DB2 error noted below. The COMP_ID column cascades to the DEPARTMENT table, but does not cascade to the EMPLOYEE table. DB2 SQL error: SQLCODE: -407, SQLSTATE: 23502, SQLERRMC: TBSPACEID=2, TABLEID=4, COLNO=0 {prepstmnt 1256737512 INSERT INTO EMPLOYEE (DEPT_ID, EMP_ID, NAME) VALUES (?, ?, ?) [params=(long) 1, (long) 1, (String) Frank]} [code=-407, state=23502]SQLCA OUTPUT[Errp=SQLDFMT1, Errd=[-2146041828, 28, 0, 0, 0, 0]] An application is provided to demonstrate the issue. To setup and unsuccessfully run demonstration with OpenJPA: 1. Add DB provider JAR(s) to the FunInheritanceJava project's build path. 2.
[jira] Created: (OPENJPA-238) Error in XMLFileHandler, failed to load field element with type org.apace.openjpa.util.StringId.
Error in XMLFileHandler, failed to load field element with type org.apace.openjpa.util.StringId. Key: OPENJPA-238 URL: https://issues.apache.org/jira/browse/OPENJPA-238 Project: OpenJPA Issue Type: Bug Components: xml store Reporter: Catalina Wei Problem reported by Ngo, Anh (full description with attachments can be found in openjpa-dev mails, subject title: xml store help? In evaluating openJPA to use for our current project. It works fine for our need with database. But I am having problem with the XMLStoreManager. I have two simple objects - Customer and User. Customer can have multiple users. I look at the object store in xml file. It stored like this: ?xml version=1.0 encoding=UTF-8? extent object class=net.iss.mss.jpa.examples.remedy.Customer oid=1 version=0 field name=customerId 1 /field field name=customerName customer1 /field field name=users element org.apache.openjpa.util.StringId:1 /element element org.apache.openjpa.util.StringId:2 /element /field /object /extent Shoud the Users element store User object? The XMLStoreManager failed to load data in because it doest not know how to create this object: org.apache.openjpa.util.StringId:1 Please help... -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-238) Error in XMLFileHandler, failed to load field element with type org.apace.openjpa.util.StringId.
[ https://issues.apache.org/jira/browse/OPENJPA-238?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Catalina Wei updated OPENJPA-238: - Attachment: XMLFileHandler.patch The attached patch has been sent to Anh Ngo, and it resolved his problem. I need some openjpa developer to verify the patch is correct before committing this patch. Error in XMLFileHandler, failed to load field element with type org.apace.openjpa.util.StringId. Key: OPENJPA-238 URL: https://issues.apache.org/jira/browse/OPENJPA-238 Project: OpenJPA Issue Type: Bug Components: xml store Reporter: Catalina Wei Attachments: XMLFileHandler.patch Problem reported by Ngo, Anh (full description with attachments can be found in openjpa-dev mails, subject title: xml store help? In evaluating openJPA to use for our current project. It works fine for our need with database. But I am having problem with the XMLStoreManager. I have two simple objects - Customer and User. Customer can have multiple users. I look at the object store in xml file. It stored like this: ?xml version=1.0 encoding=UTF-8? extent object class=net.iss.mss.jpa.examples.remedy.Customer oid=1 version=0 field name=customerId 1 /field field name=customerName customer1 /field field name=users element org.apache.openjpa.util.StringId:1 /element element org.apache.openjpa.util.StringId:2 /element /field /object /extent Shoud the Users element store User object? The XMLStoreManager failed to load data in because it doest not know how to create this object: org.apache.openjpa.util.StringId:1 Please help... -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
Re: xml store help?
Anh, I have created issue OPENJPA-238 for keeping track of this problem. The patch that I sent to you is also attached under OPENJPA-238. Catalina On 5/8/07, Ngo, Anh (ISS Southfield) [EMAIL PROTECTED] wrote: Hello, I am evaluating openJPA to use for our current project. It works fine for our need with database. But I am having problem with the XMLStoreManager. I have two simple objects – Customer and User. Customer can have multiple users. I look at the object store in xml file. It stored like this: ?xml version=1.0 encoding=UTF-8? extent object class=net.iss.mss.jpa.examples.remedy.Customer oid=1 version=0 field name=customerId 1 /field field name=customerName customer1 /field field name=users element *org.apache.openjpa.util.StringId:1* /element element *org.apache.openjpa.util.StringId:2* /element /field /object /extent Shoud the Users element store User object? The XMLStoreManager failed to load data in because it doest not know how to create* this object:org.apache.openjpa.util.StringId:1* * * Please help… * * I attached my orm.xml and persisentene.xml for your references. Sincerely, * * Anh Ngo Senior Application Programmer IBM Internet Security Systems 248 226 9059