Hi.
I've recently upgraded from jboss 4.0.3 to 4.0.4GA, and I've had some troubles getting hibernate to work correctly. I'm almost there now, except whenever I try to make changes to the database, nothing happens!?
So there must be something I'm missing..
Either my config is wrong, or my strategy is wrong.
this is my jboss-service.xml:
<server> <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.TRIM:name=HibernateSessionFactory"> <!-- Wait for the Postgres Datasource to be defined --> <!-- <depends>jboss.jca:service=RARDeployer</depends> --> <!-- <depends>jboss.jca:service=LocalTxCM,name=PostgresDS</depends> --> <depends>jboss.jca:service=DataSourceBinding,name=PostgresDS</depends> <attribute name="DatasourceName">java:/PostgresDS</attribute> <attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute> <attribute name="Username">admin</attribute> <attribute name="Password">123456</attribute> <attribute name="SessionFactoryName">java:/hibernate/TRIMSessionFactory</attribute> <!-- We do want hibernate to look everywhere for mapping files--> <attribute name="ScanForMappingsEnabled">true</attribute> <!-- We also want to see the actual SQL --> <attribute name="ShowSqlEnabled">true</attribute> <attribute name="SqlCommentsEnabled">true</attribute> <!-- Second level caching --> <attribute name="SecondLevelCacheEnabled">true</attribute> <attribute name="CacheProviderClass">org.hibernate.cache.EhCacheProvider</attribute> <attribute name="QueryCacheEnabled">false</attribute> </mbean> </server>
public boolean saveEditedRelationType ( RelationType relationType) { try { // Get session from session factory Session session = HibernateSessionFactory.currentSession(); // Tell hibernate to save to database, gets the object ID in return session.saveOrUpdate( relationType ); return true; } catch (HibernateException hex) {
This seems to work.. Is this an acceptable way to do it, or will I encounter exceptions?
session.getTransaction().begin(); session.saveOrUpdate( in ); session.getTransaction().commit();