hibernate and instance aliasing
- From: "xyzzy12@xxxxxxxxxxx" <xyzzy12@xxxxxxxxxxx>
- Date: 18 Oct 2006 12:26:23 -0700
We are having problems with instance aliasing in our application. I
was hoping that the secondary cache would fix the problem. But alas it
doesn't. Basically we create an object A and store it. Another piece
of code in the same JVM does a query and finds object A and
instanciates it. However, the application now has two instances of the
same "object" (or db record.) We need it to return the same instance.
Does hibernate support this mode?
AliasTest at = new AliasTest();
at.setName("name1");
at.setNumber(4);
{
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
session.save(at);
session.saveOrUpdate(at);
tx.commit();
session.close();
}
System.out.println("AliasTest=" + at);
AliasTest mimic;
{
Session session = factory.openSession();
mimic = (AliasTest)session.get(AliasTest.class,
at.getPid());
System.out.println("mimic=" + mimic);
System.out.println("mimic same as prev aliasTest?" + (mimic
== at));
session.close();
}
System.out.println("mimic=" + mimic);
mimic.setNumber(45);
System.out.println("mimic=" + mimic);
System.out.println("AliasTest=" + at);
System.out.println("mimic equals?"+mimic.equals(at));
System.out.println("mimic same as prev aliasTest via getNumber
check?"
+ (mimic.getNumber() == at.getNumber()));
.
- Follow-Ups:
- Re: hibernate and instance aliasing
- From: Christian Ashby
- Re: hibernate and instance aliasing
- Prev by Date: Re: Locks and transactions
- Next by Date: [Announce] Stylus Studio 2007 Reviewed by CRN Magazine
- Previous by thread: Locks and transactions
- Next by thread: Re: hibernate and instance aliasing
- Index(es):