Source code: org/hibernate/test/generatedkeys/select/SelectGeneratorTest.java
1 package org.hibernate.test.generatedkeys.select;
2
3 import org.hibernate.test.DatabaseSpecificTestCase;
4 import org.hibernate.Session;
5 import org.hibernate.cfg.Configuration;
6 import org.hibernate.dialect.Oracle9Dialect;
7 import org.hibernate.dialect.Dialect;
8 import org.hibernate.dialect.DataDirectOracle9Dialect;
9 import junit.framework.Test;
10 import junit.framework.TestSuite;
11
12 /**
13 * @author Steve Ebersole
14 */
15 public class SelectGeneratorTest extends DatabaseSpecificTestCase {
16 public SelectGeneratorTest(String x) {
17 super( x );
18 }
19
20 // TODO : need to determine appropriate physical generation strategies for select-generator testing on other databases...
21
22 protected void configure(Configuration cfg) {
23 super.configure( cfg );
24 }
25
26 public boolean appliesTo(Dialect dialect) {
27 return ( dialect instanceof Oracle9Dialect );
28 }
29
30 protected String[] getMappings() {
31 return new String[] {
32 "generatedkeys/select/MyEntity.hbm.xml"
33 };
34 }
35
36 public static Test suite() {
37 return new TestSuite( SelectGeneratorTest.class );
38 }
39
40 public void testJDBC3GetGeneratedKeysSupportOnOracle() {
41 if ( getDialect() instanceof DataDirectOracle9Dialect ) {
42 reportSkip( "DataDirect drivers known to not support JDBC3 getGeneratedKeys for Oracle", "oracle getGeneratedKeys support" );
43 return;
44 }
45 Session session = openSession();
46 session.beginTransaction();
47
48 MyEntity e = new MyEntity( "entity-1" );
49 session.save( e );
50
51 // this insert should happen immediately!
52 assertEquals( "id not generated through forced insertion", new Long(1), e.getId() );
53
54 session.delete( e );
55 session.getTransaction().commit();
56 session.close();
57 }
58 }