Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ReadOnly mapping attribute causes inserts
ReadOnly mapping attribute causes inserts [message #1095732] Tue, 27 August 2013 12:55 Go to next message
Roger Spall is currently offline Roger SpallFriend
Messages: 17
Registered: January 2013
Junior Member
I have a specific (and simplified) design that is leaving me scratching my head:

An Address object has a 1-1 relation with a Province

	<entity class="com.yamaha.progress.model.domain.bank.Province" access="FIELD">
		<table name="TST_PROVINCE"/>
		<attributes>
			<id name="oid">
				<column name="OID"/>
				<generated-value generator="MASTER_SEQ" strategy="SEQUENCE"/>
				<sequence-generator allocation-size="1" name="MASTER_SEQ" sequence-name="MASTER_SEQ"/>
			</id>
			<basic name="code">
				<column name="code"/>
			</basic>
			<basic name="name">
				<column name="name"/>
			</basic>
		</attributes>
	</entity>
	<entity class="com.yamaha.progress.model.domain.bank.Address" access="FIELD">
		<table name="TST_ADDRESS"/>
		<attributes>
			<id name="oid">
				<column name="OID"/>
				<generated-value generator="MASTER_SEQ" strategy="SEQUENCE"/>
				<sequence-generator allocation-size="1" name="MASTER_SEQ" sequence-name="MASTER_SEQ"/>
			</id>
			<basic name="street">
				<column name="street"/>
			</basic>
			<basic name="street2">
				<column name="street2"/>
			</basic>
			<basic name="city">
				<column name="city"/>
			</basic>
			<one-to-one name="province" fetch="LAZY" target-entity="com.yamaha.progress.model.domain.bank.Province">
				<join-column name="PROVINCE_OID"/>
				<cascade>
					<cascade-persist/>
				</cascade>
			</one-to-one>
		</attributes>
	</entity>


Next I have a simple Stateless Session Bean method

@Stateless
@LocalBean
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class BankManagerBean {

    public Address createAddress(String street, String street2, String city, Province province) {
        Province matchingProvince = em.find(Province.class, province.getOid());
        Address newAddress = new Address(street, street2, city, matchingProvince);
        em.persist(newAddress);
        return newAddress;
    }

.....
}


When I call this method, everything works fine (no surprises!).

Now, when I mark the Province mapping as ReadOnly and try the same Session Bean method again, Eclipselink tries to insert a Province - and my database correctly prevents a duplicate record and an exception is thrown:

	<entity class="com.yamaha.progress.model.domain.bank.Province" access="FIELD">

becomes

	<entity class="com.yamaha.progress.model.domain.bank.Province" access="FIELD" read-only="true">


Stack trace:

[8/27/13 8:43:45:745 EDT] 00000030 SystemOut     O [EL Warning]: 2013-08-27 08:43:45.745--UnitOfWork(-2126259708)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.ibm.websphere.ce.cm.DuplicateKeyException: ORA-00001: unique constraint (TRN_ADMIN.TST_PROVINCE_PK) violated

Error Code: 1
Call: INSERT INTO TST_PROVINCE (OID, code, name) VALUES (?, ?, ?)
	bind => [2, MAN, Manitoba]
Query: WriteObjectQuery(com.yamaha.progress.model.domain.bank.Province@c6ff4f37)
[8/27/13 8:43:45:746 EDT] 00000030 RegisteredSyn E   WTRN0074E: Exception caught from before_completion synchronization operation: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.ibm.websphere.ce.cm.DuplicateKeyException: ORA-00001: unique constraint (TRN_ADMIN.TST_PROVINCE_PK) violated

Error Code: 1
Call: INSERT INTO TST_PROVINCE (OID, code, name) VALUES (?, ?, ?)
	bind => [2, MAN, Manitoba]
Query: WriteObjectQuery(com.yamaha.progress.model.domain.bank.Province@c6ff4f37)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl$1.handleException(EntityManagerSetupImpl.java:692)
	at org.eclipse.persistence.transaction.AbstractSynchronizationListener.handleException(AbstractSynchronizationListener.java:275)
	at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:170)
	at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
	at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:291)
	at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:152)
	at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2338)
	at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:557)
	at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1015)
	at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:949)
	at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:438)
	at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:181)
	at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:950)
	at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:265)
	at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:579)
	at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4873)
	at com.yamaha.progress.apps.bank.EJSLocalNSLBankManagerBean_a9ecdbb0.createAddress(EJSLocalNSLBankManagerBean_a9ecdbb0.java)
	at com.yamaha.admin.jpamigration.BankTest.testCreateAddress(BankTest.java:79)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:611)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)


My client has marked a lot of their mappings as read-only as a way of identifying certain objects which should never change - the classes themselves have no setter methods either, with just an empty constructor plus one constructor which takes an oid.

What am I missing with respect to the semantics of 'read-only'?
Re: ReadOnly mapping attribute causes inserts [message #1095763 is a reply to message #1095732] Tue, 27 August 2013 13:48 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Try removing the <cascade-persist/> on the Address->Province relationship. Read-only in EclipseLink allows the object from the shared cache to be used without having to track it for changes. Cascading the persist seems to still force it into the context, which might be a bug. If removing the cascade-persist resolves the issue, please file a bug.

Best Regards,
Chris
Re: ReadOnly mapping attribute causes inserts [message #1095778 is a reply to message #1095763] Tue, 27 August 2013 14:07 Go to previous message
Roger Spall is currently offline Roger SpallFriend
Messages: 17
Registered: January 2013
Junior Member
Chris,

Correct... Removing <cascade-persist/> fixes the problem.

I will log a bug. I will have to find all of the references to read-only classes and remove their cascade-persist. The client set every relationship to be <cascade-persist/> to be compatible with Native Eclipselink (sessions / uow) and be consistent with their old way of thinking.

Roger
Previous Topic:MoxyJsonProvider UnmarshalException stackTrace logging
Next Topic:@JoinColumn @Convert
Goto Forum:
  


Current Time: Fri Apr 19 19:38:22 GMT 2024

Powered by FUDForum. Page generated in 0.02865 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top