openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devu213 <devusm...@gmail.com>
Subject Re: problem when persist object using JOINED inhertitance under 1.1.0
Date Mon, 25 Aug 2008 12:51:08 GMT

I too get the exact same problem. In fact, it behaves quite wierdly in my
case.

 I have two methods doing the exact same thing i.e insert a  Creditor object
with different ID's. With the object hierarchy below, I expect it to fire a
Customer query insert and then a creditor query insert for both the methods.

However, openJPA behaves randomly. It sometimes does it right for one
method, sometimes for the other, sometimes none at all.

One thing that's consistent is that whenever i try and insert an object with
the ID already in the database, it fires the wrong inserts and throws an
error.

Also, I'm using the exact same version you mentioned i.e 1.1.0


Here is my test code

public class BaseDAOTest {
		

	public void testCreateInheritance() {
		System.out.println("testInheritacne");
		EntityManager manager = null;
		Creditor creditor = new Creditor(new Double(1004), new Double(659), 
				"DK3", new Date(), new Date(), new Date(), "PROG", new Date());		
		try {
			
			
			//Invocations to the processing logic
			manager = FactoryTest.factory.createEntityManager();
			EntityTransaction transaction =	manager.getTransaction();
			transaction.begin();
			BaseDAO.create(manager, creditor);
			transaction.commit();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			//Do this instead of closing the manager directly on your own.

			manager.close();
		}
	}

	public void testCreateManyToOne() {
		System.out.println("manytoone");
		EntityManager manager = null;
		Creditor creditor = new Creditor(new Double(1005), new Double(126), 
				"DK3", new Date(), new Date(), new Date(), "PROG", new Date());
		
		try {
			
			//Invocations to the processing logic
			manager = FactoryTest.factory.createEntityManager();
			EntityTransaction transaction = manager.getTransaction();
			transaction.begin();
			BaseDAO.create(manager, creditor);
			
			transaction.commit();

		} catch (Exception e) {
			e.printStackTrace();
			
		} finally {
			//Do this instead of closing the manager directly on your own.
			//PersistenceBootstrapper.closeManager();
			manager.close();
		}
	}
	
	public static void main(String[] args) {
		BaseDAOTest test = new BaseDAOTest();
		test.testCreateInheritance();
		test.testCreateManyToOne();
	}
}


My object graph is as follows...

@Entity
@Table(name="Customer")
@Inheritance(strategy=InheritanceType.JOINED)
public class Customer  implements Serializable {

	@Id
	@Column(name="PBS_NO", nullable=false,length=8)
	public Double pbsNo;
	
	@Column(name="CVR_NO", nullable=false,length=8)
	private Double cvrNo;
	
	
	
	public Customer() {
		
	}
	
	public Customer(Double pbsNo, Double cvrNo, String postCode, Date
startDate,
		Date valStartDate, Date valEndDate, String updateBy, Date updateTS) {
		this.pbsNo = pbsNo;
		this.cvrNo = cvrNo;
		this.postCode = postCode;
		this.startDate = startDate;
		this.valStartDate = valStartDate;
		this.valEndDate = valEndDate;
		this.updateBy = updateBy;
		this.updateTS = updateTS;
	}
	
	<<snip>>
}



@Entity
@Table(name="CREDITOR")
@PrimaryKeyJoinColumn(name="PBS_NO", referencedColumnName="PBS_NO")
public class Creditor extends Customer implements Serializable {

	@Column(name="CRED_TYPE", nullable=false)
	private String credType;
	
	public Creditor() {
	}
	
	
	
	public Creditor(Double pbsNo, Double cvrNo, String postCode, Date
startDate,
		Date valStartDate, Date valEndDate, String updateBy, Date updateTS) {
		
		super(pbsNo, cvrNo, postCode, startDate, valStartDate, 
									valEndDate, updateBy, updateTS);
		this.credType = "Premium";
		this.billType = "MTHL";
		this.startDate = new Date();
		this.valStartDate = new Date();
		this.valEndDate = new Date();
		this.updateBy = "PROG";
		this.updateTS = new Date();
	}
	
	
	<<snip>>
	
	
}




Acton Wang wrote:
> 
> 
> hi, 
>  
>       I used 1.1.0 to try to implement a simple JOINED inhertance  using
> orm.xml:
>  
>  
>  <entity class="Parent">  <table name="Parent"/>  <inheritance
> strategy="JOINED"/>  <attributes>   <id name="partyID">    <column
> name="PARTYID" column-definition="VARCHAR(200)" nullable="false"/>   </id>
>     ...  </attributes> </entity> <entity class="Child">  <table
> name="Child"/>  <primary-key-join-column name="PARTYID"
> referenced-column-name="PARTYID"/>  <attributes>   <basic
> name="fullRegisteredName">    <column name="FULLREGISTEREDNAME"
> column-definition="VARCHAR(200)" updatable="true" insertable="true"/>  
> </basic>    .....
>     
>     when I try to persist multiple Child objects, the first one would be
> ok but the following ones will fail and from trace, it seems that it keeps
> inserting into the "Child" table 2 times instead of being inserting Parent
> table first then Child table.
>  
>     It looks no problem if I run it under 1.0.2 version. Is it a bug?
>  
> Thx
> Acton
> 

-- 
View this message in context: http://n2.nabble.com/problem-when-persist-object-using-JOINED-inhertitance-under-1.1.0-tp580291p781339.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message