[Hibernate-JIRA] Commented: (EJB-46) Property Validation should happen after PrePersist/PreUpdate
by Brian Curnow (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-46?page=com... ]
Brian Curnow commented on EJB-46:
---------------------------------
This issue (I think) is also affecting Id Classes.
I have an Invoice class which contains a one to many relationship with InvoiceLine, InvoiceLine has a composite key made up of the Invoice Id (sequence generated) and the InvoiceLine Id. I'm using the @IdClass annotation and NOT embedded ids.
I'm trying to use @PostPersist on the Invoice object to update the InvoiceLines with the sequence generated Invoice id. However, it appears that Hibernate is creating the IdClass instance before I've had a chance to update the fields on InvoiceLine:
[DEBUG] AbstractSaveEventListener - generated identifier: component[invoiceId,invoiceLineId]{invoiceLineId=1, invoiceId=null}, using strategy: org.hibernate.id.Assigned
Therefore my @PostPersist method in Invoice has no affect because I can't change the value of invoiceId on the IdClass, only on the InvoiceLine.
If you think this is a separate issue let me know and I'll open another bug.
> Property Validation should happen after PrePersist/PreUpdate
> ------------------------------------------------------------
>
> Key: EJB-46
> URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-46
> Project: Hibernate Entity Manager
> Type: Bug
> Components: EntityManager
> Versions: 3.1beta2, 3.1beta1
> Environment: MySQL4, Sun JRE5, WinXP
> Reporter: Johan Steiner
> Attachments: EJB3EventListener.patch, EJB3EventListener_v2.patch
>
>
> Hi,
> the description is from http://forum.hibernate.org/viewtopic.php?t=944964 but I'm experiencing the exact same issue.
> *********************
> Hibernate does property validation such as not null checking before it does the EJB3 callback to prepersist/preupdate. I'm not sure if there's a good reason for this, but I think it would be particularly convenient if this behavior was reversed. IMHO it seems to better fit the semantics of the PRE callbacks, and it would allow callbacks to make modifications to the objects before they are persisted or updated -- modifications that might in turn effect the property validation Hibernate is doing.
> The "audit" example in the entity manager documentation does make changes to the object. What if these changes had effected the property validation done before the callback occurred? What if the object was in an invalid state before the callback, but a valid state after the callback? The latter case is what I think would be conveniently handled if hibernate did its property validation after prepersist/preupdate.
> Just two cents worth, obviously there are workarounds. This EJB3 stuff is looking great.
> Ryan
> P.S. This might also allow those of us who assign our own IDs to objects to do so automatically within a callback.
> *********************
> In my case I'm working with an entity like:
> public class MyEntity
> {
> @Basic(temporalType = TemporalType.TIMESTAMP)
> @Column(name = "$createdOn", insertable = true, updatable = false, nullable = false)
> private Date firstPersistedOn = null;
> @Basic(temporalType = TemporalType.TIMESTAMP)
> @Column(name = "$modifiedOn", insertable = true, updatable = false, nullable = true)
> private Date lastPersistedOn = null;
> @PrePersist
> public void onPrePersist()
> {
> firstPersistedOn = new Date();
> }
> @PreUpdate
> public void onPreUpdate()
> {
> lastPersistedOn = new Date();
> }
> }
> Hibernate throws:
> org.hibernate.PropertyValueException: not-null property references a null or transient value: MyEntity.firstPersistedOn
> at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
> at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:262)
> at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:164)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
> at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:167)
> at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:113)
> at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:60)
> at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:540)
> at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:139)
> Regards,
> Johan
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
19 years, 5 months
[Hibernate-JIRA] Commented: (HHH-1921) "dirty, but no dirty properties" thrown when Interceptor resets properties.
by John Gilbert (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1921?page=c... ]
John Gilbert commented on HHH-1921:
-----------------------------------
I encounter this same issue when using Ejb3 callbacks. For example:
onPrePersist i want to encrypt a value for storage in the db
onPostPersist i want to decrypt the value so i can continue to use it in memory.
Here is a sample trace. Notice that it tries to doPreUpdate during the flush.
2006-10-31 10:13:20,948 DEBUG [net.pay.security.service.CustomerServiceBean] Invoking: net.pay.security.service.CustomerServiceBean.save
Parameters:
net.pay.security.entity.Customer@473fc2[
id=<null>
name=fred
creditCardNumber=5555-5555-5555-5555
]
2006-10-31 10:13:21,042 DEBUG [org.hibernate.impl.SessionImpl] opened session at timestamp: 4760811933609984
2006-10-31 10:13:21,042 DEBUG [org.hibernate.jdbc.JDBCContext] TransactionFactory reported no active transaction; Synchronization not registered
2006-10-31 10:13:21,042 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
2006-10-31 10:13:21,042 DEBUG [org.hibernate.jdbc.JDBCContext] successfully registered Synchronization
2006-10-31 10:13:21,042 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Adding flush() and close() synchronization
2006-10-31 10:13:21,057 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
2006-10-31 10:13:21,057 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Transaction already joined
2006-10-31 10:13:21,057 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] transient instance of: net.pay.security.entity.Customer
2006-10-31 10:13:21,057 DEBUG [org.hibernate.event.def.DefaultMergeEventListener] merging transient instance
2006-10-31 10:13:21,073 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] saving [net.pay.security.entity.Customer#<null>]
2006-10-31 10:13:21,073 DEBUG [net.pay.security.entity.Customer] doPrePersist:
net.pay.security.entity.Customer@ab48a7[
id=<null>
name=fred
creditCardNumber=NTU1NS01NTU1LTU1NTUtNTU1NQ==
]
2006-10-31 10:13:21,073 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] executing insertions
2006-10-31 10:13:21,088 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] executing identity-insert immediately
2006-10-31 10:13:21,088 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Inserting entity: net.pay.security.entity.Customer (native id)
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2006-10-31 10:13:21,088 DEBUG [org.hibernate.SQL] insert into Customer (id, name, creditCardNumber) values (null, ?, ?)
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2006-10-31 10:13:21,088 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Dehydrating entity: [net.pay.security.entity.Customer#<null>]
2006-10-31 10:13:21,088 DEBUG [org.hibernate.type.StringType] binding 'fred' to parameter: 1
2006-10-31 10:13:21,088 DEBUG [org.hibernate.type.StringType] binding 'NTU1NS01NTU1LTU1NTUtNTU1NQ==' to parameter: 2
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2006-10-31 10:13:21,088 DEBUG [org.hibernate.SQL] call identity()
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2006-10-31 10:13:21,088 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] Natively generated identity: 3
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
2006-10-31 10:13:21,088 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-10-31 10:13:21,104 DEBUG [net.pay.security.entity.Customer] doPostPersist:
net.pay.security.entity.Customer@ab48a7[
id=3
name=fred
creditCardNumber=5555-5555-5555-5555
]
2006-10-31 10:13:21,229 DEBUG [net.pay.security.service.CustomerServiceBean] Returning: net.pay.security.service.CustomerServiceBean.save
net.pay.security.entity.Customer@ab48a7[
id=3
name=fred
creditCardNumber=5555-5555-5555-5555
]
2006-10-31 10:13:21,229 DEBUG [org.hibernate.transaction.CacheSynchronization] transaction before completion callback
2006-10-31 10:13:21,229 DEBUG [org.hibernate.jdbc.JDBCContext] before transaction completion
2006-10-31 10:13:21,229 DEBUG [org.hibernate.impl.SessionImpl] before transaction completion
2006-10-31 10:13:21,229 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] automatically flushing session
2006-10-31 10:13:21,229 DEBUG [org.hibernate.impl.SessionImpl] automatically flushing session
2006-10-31 10:13:21,229 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] flushing session
2006-10-31 10:13:21,229 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time cascades
2006-10-31 10:13:21,229 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] dirty checking collections
2006-10-31 10:13:21,229 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushing entities and processing referenced collections
2006-10-31 10:13:21,229 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] net.pay.security.entity.Customer.creditCardNumber is dirty
2006-10-31 10:13:21,229 DEBUG [org.hibernate.event.def.DefaultFlushEntityEventListener] Updating entity: [net.pay.security.entity.Customer#3]
2006-10-31 10:13:21,229 DEBUG [net.pay.security.entity.Customer] doPreUpdate:
net.pay.security.entity.Customer@ab48a7[
id=3
name=fred
creditCardNumber=NTU1NS01NTU1LTU1NTUtNTU1NQ==
]
2006-10-31 10:13:21,245 ERROR [org.hibernate.AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: dirty, but no dirty properties
at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:256)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:475)
at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:3074)
at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:2632)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:1194)
at org.jboss.tm.TxManager.commit(TxManager.java:588)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.remoting.ReplicantsManagerInterceptor.invoke(ReplicantsManagerInterceptor.java:51)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:167)
at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:100)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
at $Proxy64.save(Unknown Source)
at net.pay.security.service.CustomerServiceTest.testSave(CustomerServiceTest.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.extensions.TestSetup.run(TestSetup.java:23)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> "dirty, but no dirty properties" thrown when Interceptor resets properties.
> ---------------------------------------------------------------------------
>
> Key: HHH-1921
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1921
> Project: Hibernate3
> Type: Bug
> Components: core
> Versions: 3.2.0.cr2
> Environment: java version "1.5.0_07"
> Hibernate 3.2.cr2
> Reporter: Josh Moore
> Fix For: 3.2.1
> Attachments: InterceptorTest.java, ResetInterceptor.java, dirtybutnotdirty.zip
>
>
> When Interceptor.onfindDirty() resets properties to their DB value, the check in DefaultFlushEntityEventListener.scheduleUpdate:
> // if it was dirtied by a collection only
> int[] dirtyProperties = event.getDirtyProperties();
> if ( event.isDirtyCheckPossible() && dirtyProperties==null ) {
> if ( !event.hasDirtyCollection() ) {
> throw new AssertionFailure("dirty, but no dirty properties");
> }
> dirtyProperties = ArrayHelper.EMPTY_INT_ARRAY;
> }
> fails needlessly.
> Attached test has been confirmed against SVN TRUNK:
> URL: http://anonhibernate.labs.jboss.com/trunk/Hibernate3
> Revision: 10125
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
19 years, 5 months
[Hibernate-JIRA] Created: (HHH-2198) Multiple Primary Keys Composite-id Mapping problem
by David Chao (JIRA)
Multiple Primary Keys Composite-id Mapping problem
--------------------------------------------------
Key: HHH-2198
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2198
Project: Hibernate3
Type: Bug
Versions: 3.2.0.ga
Environment: JRE 1.5.0, SQLServer 2000, Window 2000
Reporter: David Chao
Hi All,
I have 3 tables with multiple primary keys and trying to get composite-id to work. Here are the tables.
Table: tb_hl7MSH (regular id)
Primary key: reportID
Table: tb_hl7PID (composite-id mapping)
Primary Key: reportID, setIDPID
Table: tb_hl7OBR (composite-id mapping)
Primary Key: reportID, setIDPID, setIDOBR
<class name="com.sql.Hl7MSHData" table="tb_hl7MSH">
<id name="MSHId" type="long" column="reportID" >
<generator class="native"/>
</id>
<set name="HL7MSHtoPID" table="tb_hl7PID" lazy="true" cascade="all">
<key column="reportID"/>
<one-to-many class="com.sql.Hl7PIDData"/>
</set>
</class>
<class name="com.sql.Hl7PIDData" table="tb_hl7PID">
<composite-id name="PIDDataPK" class="com.sql.Hl7PIDDataPK">
<key-property name="PIDId" column="setIDPID" type="long"/>
<key-many-to-one name="MSHRec" class="com.sql.Hl7MSHData">
<column name="reportID"/>
</key-many-to-one>
</composite-id>
<set name="HL7PIDtoOBR" table="tb_hl7OBR" lazy="true" cascade="all">
<key>
<column name="reportID"/>
<column name="setIDPID"/>
</key>
<one-to-many class="com.sql.Hl7OBRData"/>
</set>
</class>
<class name="com.sql.Hl7OBRData" table="tb_hl7OBR">
<composite-id name="OBRDataPK" class="com.sql.Hl7OBRDataPK">
<key-property name="OBRId" column="setIDOBR" type="long"/>
<key-many-to-one name="PIDRec" class="com.sql.Hl7PIDData">
<column name="reportID"/>
<column name="setIDPID"/>
</key-many-to-one>
</composite-id>
</class>
Code:
public class Hl7MSHData implements Serializable {
static final long serialVersionUID = 4334341L;
private Long MSHId;
private Set HL7MSHtoPID = new HashSet();
public Hl7MSHData () {
}
public int hashCode() {
return MSHId.hashCode();
}
public boolean equals(Object other) {
if ( !(other instanceof Hl7MSHData) ) return false;
Hl7MSHData c = (Hl7MSHData) other;
return c.getMSHId().equals(MSHId);
}
}
public class Hl7PIDData implements Serializable {
static final long serialVersionUID = 4334323L;
private String id;
private Hl7PIDDataPK PIDDataPK;
private Set HL7PIDtoOBR = new HashSet();
public Hl7PIDData () {
this.id = java.util.UUID.randomUUID().toString();
}
public int hashCode() {
System.out.println("PID Id: " + id.toString());
return id.hashCode();
}
public boolean equals(Object other) {
if ( !(other instanceof Hl7PIDData) ) return false;
Hl7PIDData c = (Hl7PIDData) other;
boolean flag = c.getPIDDataPK().getPIDId().equals(
PIDDataPK.getPIDId()) &&
c.getPIDDataPK().getMSHRec().getMSHId().equals(
PIDDataPK.getMSHRec().getMSHId());
System.out.println("PID Stat: " + flag);
return flag;
}
---- All the setter and getter method
}
public class Hl7PIDDataPK implements Serializable {
static final long serialVersionUID = 4334323L;
private String id;
private Long PIDId;
private Hl7MSHData MSHRec;
public Hl7PIDDataPK () {
this.id = java.util.UUID.randomUUID().toString();
}
public int hashCode() {
System.out.println("PIDPK Id: " + id.toString());
return id.hashCode();
}
public boolean equals(Object other) {
if ( !(other instanceof Hl7PIDDataPK) ) return false;
Hl7PIDDataPK c = (Hl7PIDDataPK) other;
boolean flag = c.getPIDId().equals(PIDId) &&
c.getMSHRec().getMSHId().equals(MSHRec.getMSHId());
System.out.println("PID Stat: " + flag);
return flag;
}
---- All the setter and getter method
}
public class Hl7OBRData implements Serializable {
static final long serialVersionUID = 4334342L;
private Hl7OBRDataPK OBRDataPK;
private String id;
public Hl7OBRData() {
this.id = java.util.UUID.randomUUID().toString();;
}
public int hashCode() {
System.out.println("OBR Id: " + id.toString());
return id.hashCode();
}
public boolean equals(Object other) {
if ( !(other instanceof Hl7OBRData) ) return false;
Hl7OBRData c = (Hl7OBRData) other;
boolean flag = c.getOBRDataPK().getOBRId().equals
(OBRDataPK.getOBRId()) &&
c.getOBRDataPK().getPIDRec().getPIDDataPK().getPIDId().equals(
OBRDataPK.getPIDRec().getPIDDataPK().getPIDId()) &&
c.getOBRDataPK().getPIDRec().getPIDDataPK().getMSHRec().getMSHId().equals(
OBRDataPK.getPIDRec().getPIDDataPK().getMSHRec().getMSHId());
System.out.println("OBR Stat: " + flag);
return flag;
}
---- All the setter and getter method
}
public class Hl7OBRDataPK implements Serializable {
static final long serialVersionUID = 4334343L;
private Long OBRId;
private String id;
private Hl7PIDData PIDRec;
public Hl7OBRDataPK () {
this.id = java.util.UUID.randomUUID().toString();
}
public int hashCode() {
System.out.println("OBRPK Id: " + id.toString());
return id.hashCode();
}
public boolean equals(Object other) {
if ( !(other instanceof Hl7OBRDataPK) ) return false;
Hl7OBRDataPK c = (Hl7OBRDataPK) other;
boolean flag = c.getOBRId().equals(OBRId) &&
c.getPIDRec().getPIDDataPK().getPIDId().equals(PIDRec.getPIDDataPK().getPIDId()) &&
c.getPIDRec().getPIDDataPK().getMSHRec().getMSHId().equals(PIDRec.getPIDDataPK().getMSHRec().getMSHId());
System.out.println("OBRPK Stat: " + flag);
return flag;
}
---- All the setter and getter method
}
Main Class:
public class build_objects {
public static void main(String[] args) {
try {
build_objects mgr = new build_objects();
mgr.createAndStoreEvent();
HibernateUtil.getSessionFactory().close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private void createAndStoreEvent() {
// Session session = HibernateSessionFactory.getSession();
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List ReportList = session
.createQuery("from Hl7MSH")
.list();
// Iterating over the elements in the set
Iterator ti = ReportList.iterator();
while (ti.hasNext()) {
Hl7Report ReportInfo = (Hl7Report) ti.next();
//Object other = ti.next();
//Hl7OBRDataPK obrdata = (Hl7OBRDataPK) other;
//Long reportID = obrdata.getOBRId();
// String reportID = temp[0].toString();
//Hl7Report ReportInfo = (Hl7Report) session.load(Hl7Report.class,
// reportID);
System.out.println("REPORT Report ID: " + ReportInfo.getReportID());
Set Hl7MSHSet = ReportInfo.getHl7RptMSH();
// Iterating over the elements in the set
Iterator it = Hl7MSHSet.iterator();
while (it.hasNext()) {
Hl7MSHData Hl7MSHInfo = (Hl7MSHData) it.next();
Set Hl7PIDSet = Hl7MSHInfo.getHL7MSHtoPID();
System.out.println("MSH ID:" + Hl7MSHInfo.getMSHId());
System.out.println("MSH b:" + Hl7MSHInfo.getCm_Type());
System.out
.println("MSH c:" + Hl7MSHInfo.getDateTimeofMessage());
// Iterating over the elements in the set
Iterator itm = Hl7PIDSet.iterator();
while (itm.hasNext()) {
Hl7PIDData Hl7PIDInfo = (Hl7PIDData) itm.next();
System.out.println("PID zz:" + Hl7PIDInfo.getGivenName());
System.out.println("PID z1:"
+ Hl7PIDInfo.getPatientIDInternalID());
Set HL7OBRSet = Hl7PIDInfo.getHL7PIDtoOBR();
// Iterating over the elements in the set
Iterator ito = HL7OBRSet.iterator();
while (ito.hasNext()) {
// Get element
Hl7OBRData Hl7OBRInfo = (Hl7OBRData) ito.next();
System.out.println("OBR Result Stat: "
+ Hl7OBRInfo.getResultStatus());
}
}
}
}
session.getTransaction().commit();
}
}
Was able to retrieve the first set of rows for all the tables but second set isn't coming thru for OBR. I get everything but the OBR records. I verify in the database that the row exist. Also, how do you "Select" or "Join" to a composite-id table when the ids are located in the PK table? I'm using SQLServer database. Any help would be appreciated. Thanks in advance.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
19 years, 5 months