Java Reference
In-Depth Information
tx = session . beginTransaction ();
Query query = session . createQuery (
"select p from Person p order by p.lastName" );
List < Person > list = query . list ();
System . out . println ( "There are " + list . size () + " persons:" );
list . forEach ( p ->
System . out . println (
p . getFirstName () + ' ' + p . getLastName ())
);
System . out . println ();
} finally
finally {
iif ( session != null
null ) {
session . close ();
}
}
}
}
For Hibernate, the configuration file is named hibernate.cfg.xml , and might look like this:
<hibernate-configuration>
<session-factory>
<!-- Using HSQLDB -->
<property name="connection.url">jdbc:hsqldb:tmp/hibdemo.db
</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver
</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect
</property>
<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.jdbc.batch_size">0</property>
<!-- Make hibernate manage session contexts -->
<property name="hibernate.current_session_context_class">
org.hibernate.context.ThreadLocalSessionContext</property>
<!-- Nice setting for dev; do not use in production! :-) -->
<property name="hibernate.hbm2ddl.auto">create-drop</property>
Search WWH ::




Custom Search