Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate does not commit data
    primarykey
    data
    text
    <p><br /> I'm trying to write a web service to store some data using jBoss 4.2.3 and Oracle.<br /> I suppose to use Hibernate with CMT and seems to me it doesn't commit the transaction. I have the following code:<br /><br /> <strong>Bean</strong>:</p> <pre><code>@Stateless @TransactionManagement(TransactionManagementType.CONTAINER) public class ZzzBean implements ZzzI { public ZzzBean() { } @TransactionAttribute(TransactionAttributeType.REQUIRED) public int addZzz() { try { Zzz z = new Zzz(); z.setA("a"); z.setI(new BigDecimal(11)); HibernateUtil.getSessionFactory().getCurrentSession().save(z); } catch (Exception ex) { ex.printStackTrace(); } return 1; } } </code></pre> <p><strong>Interface</strong>:</p> <pre><code>@Local public interface ZzzI { int addZzz(); } </code></pre> <p>My <strong>session factory</strong> class:</p> <pre><code>public class HibernateUtil { private static SessionFactory sessionFactory; private static Configuration configuration; static { try { configuration = new AnnotationConfiguration().configure(); sessionFactory = configuration.buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } </code></pre> <p><strong>hibernate.cfg.xml</strong> has following:</p> <pre><code>&lt;session-factory&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt; &lt;property name="hibernate.connection.driver_class"&gt;oracle.jdbc.OracleDriver&lt;/property&gt; &lt;property name="hibernate.connection.url"&gt;jdbc:oracle:thin:@//my_host&lt;/property&gt; &lt;property name="hibernate.connection.username"&gt;my_user&lt;/property&gt; &lt;property name="hibernate.connection.password"&gt;my_pass&lt;/property&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;property name="current_session_context_class"&gt;jta&lt;/property&gt; &lt;property name="transaction.factory_class"&gt;org.hibernate.transaction.CMTTransactionFactory&lt;/property&gt; &lt;property name="transaction.manager_lookup_class"&gt;org.hibernate.transaction.JBossTransactionManagerLookup&lt;/property&gt; &lt;mapping resource="com/example/Zzz.hbm.xml" /&gt; &lt;/session-factory&gt; </code></pre> <p><strong>Mapping</strong> file:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.example.Zzz" table="ZZZ"&gt; &lt;id name="i" type="big_decimal"&gt; &lt;column name="i" precision="22" scale="0" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; &lt;property name="a" type="string"&gt; &lt;column name="a" length="20" /&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p><strong>Entity</strong> class:</p> <pre><code>@Entity @Table(name = "ZZZ") public class Zzz implements Serializable { private static final long serialVersionUID = -4165930294512113400L; private BigDecimal i; private String a; public Zzz(){} @Id @Column(name = "i", unique = true, nullable = false, precision = 22, scale = 0) public BigDecimal getI() { return this.i; } @Column(name = "a", length = 20) public String getA() { return this.a; } public void setI(BigDecimal i) { this.i = i; } public void setA(String a) { this.a = a; } } </code></pre> <p>And the <strong>web service</strong> code:</p> <pre><code>@WebService(name = "Zzz", serviceName = "Zzz") @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @Stateless public class ZzzWS { @EJB(beanName = "ZzzBean") ZzzI z; @WebMethod public int addZzz() { return z.addVisit(); } } </code></pre> <p>When I call web service method I have the following output:</p> <pre><code>13:43:52,671 INFO [Version] Hibernate Annotations 3.2.1.GA 13:43:52,682 INFO [Environment] Hibernate 3.2.4.sp1 13:43:52,686 INFO [Environment] hibernate.properties not found 13:43:52,687 INFO [Environment] Bytecode provider name : javassist 13:43:52,691 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling 13:43:52,753 INFO [Configuration] configuring from resource: /hibernate.cfg.xml 13:43:52,753 INFO [Configuration] Configuration resource: /hibernate.cfg.xml 13:43:52,869 INFO [Configuration] Reading mappings from resource : com/example/Zzz.hbm.xml 13:43:52,884 INFO [Configuration] Configured SessionFactory: null 13:43:53,022 INFO [HbmBinder] Mapping class: com.example.Zzz -&gt; ZZZ 13:43:53,124 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!) 13:43:53,124 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20 13:43:53,124 INFO [DriverManagerConnectionProvider] autocommit mode: false 13:43:53,168 INFO [DriverManagerConnectionProvider] using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@//my_host 13:43:53,168 INFO [DriverManagerConnectionProvider] connection properties: {user=***, password=***} 13:43:53,739 INFO [SettingsFactory] RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options 13:43:53,739 INFO [SettingsFactory] JDBC driver: Oracle JDBC driver, version: 11.2.0.2.0 13:43:53,754 INFO [Dialect] Using dialect: org.hibernate.dialect.Oracle10gDialect 13:43:53,758 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.CMTTransactionFactory 13:43:53,760 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup 13:43:53,761 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup 13:43:53,761 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled 13:43:53,761 INFO [SettingsFactory] Automatic session close at end of transaction: disabled 13:43:53,762 INFO [SettingsFactory] JDBC batch size: 15 13:43:53,762 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled 13:43:53,762 INFO [SettingsFactory] Scrollable result sets: enabled 13:43:53,762 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled 13:43:53,762 INFO [SettingsFactory] Connection release mode: auto 13:43:53,763 INFO [SettingsFactory] Default batch fetch size: 1 13:43:53,763 INFO [SettingsFactory] Generate SQL with comments: disabled 13:43:53,763 INFO [SettingsFactory] Order SQL updates by primary key: disabled 13:43:53,763 INFO [SettingsFactory] Order SQL inserts for batching: disabled 13:43:53,763 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 13:43:53,765 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory 13:43:53,765 INFO [SettingsFactory] Query language substitutions: {} 13:43:53,765 INFO [SettingsFactory] JPA-QL strict compliance: disabled 13:43:53,765 INFO [SettingsFactory] Second-level cache: enabled 13:43:53,765 INFO [SettingsFactory] Query cache: disabled 13:43:53,765 INFO [SettingsFactory] Cache provider: org.hibernate.cache.NoCacheProvider 13:43:53,765 INFO [SettingsFactory] Optimize cache for minimal puts: disabled 13:43:53,765 INFO [SettingsFactory] Structured second-level cache entries: disabled 13:43:53,769 INFO [SettingsFactory] Echoing all SQL to stdout 13:43:53,769 INFO [SettingsFactory] Statistics: disabled 13:43:53,769 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled 13:43:53,769 INFO [SettingsFactory] Default entity-mode: pojo 13:43:53,769 INFO [SettingsFactory] Named query checking : enabled 13:43:53,789 INFO [SessionFactoryImpl] building session factory 13:43:54,121 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured 13:43:54,122 INFO [NamingHelper] JNDI InitialContext properties:{} 13:43:54,174 INFO [STDOUT] Hibernate: insert into ZZZ (a, i) values (?, ?) </code></pre> <p>But database does not have a new record even when I stop jBoss. Where is my fault? Please help.</p> <p>P.S. When I am not using CMT and write code like:</p> <pre><code>tx = session.beginTransaction(); session.persist(...); tx.commit(); </code></pre> <p>all works fine.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload