[hibernate-commits] Hibernate SVN: r10596 - trunk/Hibernate3/test/org/hibernate/test/legacy
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue Oct 17 17:29:46 EDT 2006
Author: steve.ebersole at jboss.com
Date: 2006-10-17 17:29:45 -0400 (Tue, 17 Oct 2006)
New Revision: 10596
Modified:
trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java
trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java
Log:
fixed minor issue in use of save
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java 2006-10-17 21:18:17 UTC (rev 10595)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java 2006-10-17 21:29:45 UTC (rev 10596)
@@ -518,26 +518,6 @@
s.close();
}
- /*public void testCascading2() throws Exception {
- Session s = sessionsopenSession();
- Detail d1 = new Detail();
- Detail d2 = new Detail();
- Master m = new Master();
- m.getMoreDetails().add(d1);
- m.getMoreDetails().add(d2);
- Serializable mid = s.save(m);
- s.flush();
- s.connection().commit();
- s.close();
- s = sessionsopenSession();
- m = (Master) s.load(Master.class, mid);
- assertTrue( m.getMoreDetails().size()==2, "cascade save" );
- s.delete(m);
- s.flush();
- s.connection().commit();
- s.close();
- }*/
-
public void testNamedQuery() throws Exception {
Session s = openSession();
Query q = s.getNamedQuery("all_details");
@@ -546,111 +526,23 @@
s.close();
}
-
-// This stuff is tested elsewhere
-// public void testSerialization() throws Exception {
-//
-// if (getDialect() instanceof HSQLDialect) return;
-//
-// Session s = openSession();
-// Master m = new Master();
-// Detail d1 = new Detail();
-// Detail d2 = new Detail();
-// Serializable mid = s.save(m);
-// d1.setMaster(m);
-// d2.setMaster(m);
-// m.addDetail(d1);
-// m.addDetail(d2);
-// if ( (getDialect() instanceof SybaseDialect) || (getDialect() instanceof DerbyDialect) ) {
-// s.save(d1);
-// }
-// else {
-// s.save( d1, new Long(666) );
-// }
-// //s.save(d2);
-// s.flush();
-// s.connection().commit();
-// s.disconnect();
-// ByteArrayOutputStream os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// byte[] bytes = os.toByteArray();
-// System.out.println(bytes.length);
-// s = (Session) new ObjectInputStream( new ByteArrayInputStream(bytes) ).readObject();
-// s.reconnect();
-// Master m2 = (Master) s.load(Master.class, mid);
-// assertTrue( "serialized state", m2.getDetails().size()==2 );
-// Iterator iter = m2.getDetails().iterator();
-// while ( iter.hasNext() ) {
-// Detail d = (Detail) iter.next();
-// assertTrue( "deserialization", d.getMaster()==m2 );
-// try {
-// s.getIdentifier(d);
-// s.delete(d);
-// }
-// catch (Exception e) {}
-// }
-// s.delete(m2);
-// s.flush();
-// s.connection().commit();
-// s.close();
-//
-// s = openSession();
-// mid = s.save( new Master() );
-// Serializable mid2 = s.save( new Master() );
-// s.flush();
-// s.connection().commit();
-// s.disconnect();
-// os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// bytes = os.toByteArray();
-// System.out.println(bytes.length);
-// s = (Session) new ObjectInputStream( new ByteArrayInputStream(bytes) ).readObject();
-// s.reconnect();
-// s.delete( s.load(Master.class, mid) );
-// s.delete( s.load(Master.class, mid2) );
-// s.flush();
-// s.connection().commit();
-// s.close();
-//
-// s = openSession();
-// s.connection(); //force session to grab a connection
-// try {
-// os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// }
-// catch (Exception e) {
-// assertTrue("illegal state", e instanceof IllegalStateException );
-// s.connection().commit();
-// s.close();
-// return;
-// }
-// assertTrue("serialization should have failed", false);
-//
-// }
-
public void testUpdateLazyCollections() throws Exception {
-
Session s = openSession();
Master m = new Master();
+ Serializable mid = s.save(m);
Detail d1 = new Detail();
Detail d2 = new Detail();
d2.setX(14);
- Serializable mid = s.save(m);
- //s.flush();
d1.setMaster(m);
d2.setMaster(m);
+ s.save(d1);
+ s.save(d2);
m.addDetail(d1);
m.addDetail(d2);
- if ( (getDialect() instanceof SybaseDialect) || (getDialect() instanceof DerbyDialect) ) {
- s.save(d1); s.save(d2);
- }
- else {
- s.save( d1, new Long(666) );
- s.save( d2, new Long(667) );
- }
s.flush();
s.connection().commit();
s.close();
+
s = openSession();
m = (Master) s.load(Master.class, mid);
s.connection().commit();
@@ -671,7 +563,6 @@
s.flush();
s.connection().commit();
s.close();
-
}
public void testMultiLevelCascade() throws Exception {
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java 2006-10-17 21:18:17 UTC (rev 10595)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java 2006-10-17 21:29:45 UTC (rev 10596)
@@ -16,11 +16,10 @@
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.LockMode;
+import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Expression;
-import org.hibernate.Transaction;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.SybaseDialect;
public class MultiTableTest extends LegacyTestCase {
@@ -159,15 +158,8 @@
}
public void testQueries() throws Exception {
-
Session s = openSession();
- Long id = new Long(1);
- if (getDialect() instanceof SybaseDialect) { // chekked because identity insert not possible with predefined value.
- id = (Long) s.save( new TrivialClass() );
- }
- else{
- s.save( new TrivialClass(), id );
- }
+ Long id = ( Long ) s.save( new TrivialClass() );
s.flush();
s.connection().commit();
@@ -191,17 +183,11 @@
}
public void testConstraints() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
SubMulti sm = new SubMulti();
sm.setAmount(66.5f);
- if ( getDialect() instanceof SybaseDialect ) {
- s.save(sm);
- }
- else {
- s.save( sm, new Long(2) );
- }
+ s.save( sm );
t.commit();
s.close();
s = openSession();
@@ -212,39 +198,21 @@
}
public void testMultiTable() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- Serializable sid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- sid = s.save(simp);
- }
- else {
- mid = new Long(123);
- s.save(multi, mid);
- sid = new Long(1234);
- s.save(simp, sid);
- }
+
+ Serializable mid = s.save(multi);
+ Serializable sid = s.save(simp);
+
SubMulti sm = new SubMulti();
sm.setAmount(66.5f);
- Serializable smid;
- if (getDialect() instanceof SybaseDialect) {
- smid = s.save(sm);
- }
- else {
- smid = new Long(2);
- s.save(sm, smid);
- }
+ Serializable smid = s.save(sm);
t.commit();
s.close();
@@ -483,30 +451,19 @@
}
public void testMultiTableCollections() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
assertTrue( s.find("from Top").size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- Serializable sid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- sid = s.save(simp);
- }
- else {
- mid = new Long(123);
- sid = new Long(1234);
- s.save(multi, mid);
- s.save(simp, sid);
- }
+
+ s.save(multi);
+ s.save(simp);
+
Lower ls = new Lower();
ls.setOther(ls);
ls.setAnother(ls);
@@ -516,14 +473,7 @@
ls.setSet(set);
set.add(multi);
set.add(simp);
- Serializable id;
- if ( getDialect() instanceof SybaseDialect ) {
- id = s.save(ls);
- }
- else {
- id = new Long(2);
- s.save( ls, new Long(2) );
- }
+ Serializable id = s.save(ls);
t.commit();
s.close();
assertTrue( ls.getOther()==ls && ls.getAnother()==ls && ls.getYetanother()==ls );
@@ -548,39 +498,22 @@
}
public void testMultiTableManyToOne() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
assertTrue( s.find("from Top").size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- }
- else {
- mid = new Long(123);
- s.save(multi, mid);
- }
+ s.save(multi);
Lower ls = new Lower();
ls.setOther(ls);
ls.setAnother(multi);
ls.setYetanother(ls);
ls.setName("Less Simple");
- Serializable id;
- if ( getDialect() instanceof SybaseDialect ) {
- id = s.save(ls);
- }
- else {
- id = new Long(2);
- s.save( ls, new Long(2) );
- }
+ Serializable id = s.save(ls);
t.commit();
s.close();
assertTrue( ls.getOther()==ls && ls.getAnother()==multi && ls.getYetanother()==ls );
More information about the hibernate-commits
mailing list