Persist Data from Tapestry with Hibernate Issue - java

I've read many of the other examples, but cannot seem to persist my data with hibernate.
I have code here that creates the objects:
package com.example.leaderboardApp.pages;
import com.example.leaderboardApp.utility.Competitor;
import org.apache.tapestry5.annotations.RequestParameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.annotations.ActivationRequestParameter;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
public class Ws {
#ActivationRequestParameter("hipchat_id") private int hipchat_id;
#ActivationRequestParameter("name") private String name;
#ActivationRequestParameter("dips") private int dips;
#Property
private Competitor competitor;
#Inject
private Session session;
#SetupRender
void appUpdate() {
competitor = new Competitor(hipchat_id, name);
competitor.addReps(dips);
System.out.println(competitor);
}
#CommitAfter
Object onSuccess() {
session.persist(competitor);
return hipchat_id;
}
}
Then, I have the object class itself:
package com.example.leaderboardApp.utility;
import java.util.ArrayList;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;
import com.example.leaderboardApp.pages.Index;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
#Entity()
public class Competitor {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#NonVisual
public int hipchat_id;
#Validate("required")
private String name;
private int score;
private int goal = 14000;
private int progress = score/goal;
public Competitor(int hipchat_id, String name) {
this.hipchat_id = hipchat_id;
this.name = name;
}
public String getName() {
return this.name;
}
public void addReps(int repetitions) {
this.score += repetitions;
}
And finally my config page:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:./target/work/leaderboardApp;shutdown=true</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping package="com.example.leaderboardApp.utility.Competitor" />
</session-factory>
</hibernate-configuration>
When I run everything, this is what I get spit back from the process:
[INFO] Started SelectChannelConnector#0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] common.Version Hibernate Commons Annotations 3.2.0.Final
[INFO] cfg.Environment Hibernate 3.6.0.Final
[INFO] cfg.Environment hibernate.properties not found
[INFO] cfg.Environment Bytecode provider name : javassist
[INFO] cfg.Environment using JDK 1.4 java.sql.Timestamp handling
[INFO] cfg.Configuration configuring from resource: /hibernate.cfg.xml
[INFO] cfg.Configuration Configuration resource: /hibernate.cfg.xml
[WARN] util.DTDEntityResolver recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
[INFO] cfg.Configuration Mapping package com.example.leaderboardApp.utility.Competitor
[WARN] cfg.AnnotationBinder Package not found or wo package-info.java: com.example.leaderboardApp.utility.Competitor
[INFO] cfg.Configuration Configured SessionFactory: null
[INFO] cfg.Configuration Mapping package com.example.leaderboardApp.entities
[WARN] cfg.AnnotationBinder Package not found or wo package-info.java: com.example.leaderboardApp.entities
[INFO] cfg.Configuration Hibernate Validator not found: ignoring
[INFO] search.HibernateSearchEventListenerRegister Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
[INFO] connection.DriverManagerConnectionProvider Using Hibernate built-in connection pool (not for production use!)
[INFO] connection.DriverManagerConnectionProvider Hibernate connection pool size: 20
[INFO] connection.DriverManagerConnectionProvider autocommit mode: false
[INFO] connection.DriverManagerConnectionProvider using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:./target/work/leaderboardApp;shutdown=true
[INFO] connection.DriverManagerConnectionProvider connection properties: {user=, password=****}
[INFO] cfg.SettingsFactory Database ->
name : HSQL Database Engine
version : 2.3.2
major : 2
minor : 3
[INFO] cfg.SettingsFactory Driver ->
name : HSQL Database Engine Driver
version : 2.3.2
major : 2
minor : 3
[INFO] dialect.Dialect Using dialect: org.hibernate.dialect.HSQLDialect
[INFO] transaction.TransactionFactoryFactory Using default transaction strategy (direct JDBC transactions)
[INFO] transaction.TransactionManagerLookupFactory No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[INFO] cfg.SettingsFactory Automatic flush during beforeCompletion(): disabled
[INFO] cfg.SettingsFactory Automatic session close at end of transaction: disabled
[INFO] cfg.SettingsFactory JDBC batch size: 15
[INFO] cfg.SettingsFactory JDBC batch updates for versioned data: disabled
[INFO] cfg.SettingsFactory Scrollable result sets: enabled
[INFO] cfg.SettingsFactory JDBC3 getGeneratedKeys(): enabled
[INFO] cfg.SettingsFactory Connection release mode: auto
[INFO] cfg.SettingsFactory Default batch fetch size: 1
[INFO] cfg.SettingsFactory Generate SQL with comments: disabled
[INFO] cfg.SettingsFactory Order SQL updates by primary key: disabled
[INFO] cfg.SettingsFactory Order SQL inserts for batching: disabled
[INFO] cfg.SettingsFactory Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[INFO] ast.ASTQueryTranslatorFactory Using ASTQueryTranslatorFactory
[INFO] cfg.SettingsFactory Query language substitutions: {}
[INFO] cfg.SettingsFactory JPA-QL strict compliance: disabled
[INFO] cfg.SettingsFactory Second-level cache: enabled
[INFO] cfg.SettingsFactory Query cache: disabled
[INFO] cfg.SettingsFactory Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
[INFO] cfg.SettingsFactory Optimize cache for minimal puts: disabled
[INFO] cfg.SettingsFactory Structured second-level cache entries: disabled
[INFO] cfg.SettingsFactory Echoing all SQL to stdout
[INFO] cfg.SettingsFactory Statistics: disabled
[INFO] cfg.SettingsFactory Deleted entity synthetic identifier rollback: disabled
[INFO] cfg.SettingsFactory Default entity-mode: pojo
[INFO] cfg.SettingsFactory Named query checking : enabled
[INFO] cfg.SettingsFactory Check Nullability in Core (should be disabled when Bean Validation is on): enabled
[INFO] impl.SessionFactoryImpl building session factory
[INFO] impl.SessionFactoryObjectFactory Not binding factory to JNDI, no JNDI name configured
[INFO] hbm2ddl.SchemaUpdate Running hbm2ddl schema update
[INFO] hbm2ddl.SchemaUpdate fetching database metadata
[INFO] hbm2ddl.SchemaUpdate updating schema
[INFO] hbm2ddl.SchemaUpdate schema update complete
[INFO] HibernateCoreModule.HibernateSessionSource Hibernate startup: 122 ms to configure, 371 ms overall.
[INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: (none)
com.example.leaderboardApp.utility.Competitor#3d03f309
[INFO] AppModule.TimingFilter Request time: 954 ms
It looks like above the object is properly created, but I am really struggling on the persistence side. Any help would be greatly appreciated.

Okay, unfortunately, my post must not have gotten enough attention here, but I have done tons of research around this area now and thought I would share what I found.
First, I changed to SQL instead of using hibernates native database. This sped things up 10 fold. I understand it may not be the best solution for all applications, but for smaller or non-essential applications, its the easiest.
Below my Hibernate config file:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/leaderboardApp</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping class="com.example.leaderboardApp.utility.Competitor"/>
<mapping class="com.example.leaderboardApp.utility.Record"/>
</session-factory>
</hibernate-configuration>
Note that the port will usually be 3306 if you are running locally. If that is your goal, make sure to set up your MySQL database as such (and look for the port it will be listening on). You will have to install the JDBC jar. The easiest way is if you have homebrew. Note it is a two step installation: https://github.com/gbeine/homebrew-java
brew tap gbeine/homebrew-java
brew install mysql-connector-java
Below your main configuration, you have to tell Hibernate what your classes are. This is the mapping class section. I have seen a million implementations of this with package mapping, etc. Again, for a simple app, this is easiest.
Once you have mapped your class in the Hibernate config file, go back to your .java class to structure it in a way Hibernate will associate it properly with your MySQL tables.
#Entity
#Table(name="competitors")
public class Competitor {
#Id
#Column(name="hipchat_id", unique=true, nullable=false)
public int hipchat_id;
#Column(name="name")
#Validate("required")
private String name;
#Column(name="score")
private int score;
#Column(name="goal")
private int goal = 14000;
#Column(name="progress")
private int progress = score/goal;
When you declare each variable, you need to assure that you have the correct data type. You can see here that I have incorrectly (on purpose) declared progress an int when it should be a double.
Note that I have declared these variables as columns and the name of the column in the DB. This is essential and you will have many headaches without this.
Finally, when you go to save your data, I found there are tons of stackoverflow descriptions for forms, but none for backend initiated DB saves. So, I have included that code below, too:
public class Ws {
#ActivationRequestParameter("hipchat_id") private int hipchat_id;
#ActivationRequestParameter("name") private String name;
#ActivationRequestParameter("dips") private int dips;
#Property
private Competitor competitor;
#Inject
private Session session;
#SetupRender
#CommitAfter
void appUpdate() {
session.saveOrUpdate(new Competitor(hipchat_id, name, dips));
session.save(new Record(hipchat_id, dips));
}
}
Basically, you have to start a session with #Inject. Then, as this is a WS that processes URL parameters, I use #SetupRender to start the method upon page render. Many times, people put the #CommitAfter after this entire method with an OnSuccess method, but for java initiated sessions, this does not work. So for these, I put it directly after the SetupRender to make sure that all the session saves/edits/deletes I perform during the method are committed afterwards. Without this, your program will quietly fail. Nothing will jump out at you and your data will not be saved.
I apologize as I am a bit of a newb at development so I may not have described everything here optimally, but hope it can help someone down the road.

Related

Is it possible to override persistence.xml partially in Quarkus application properties?

I'm migrating a JEE / JBOSS project to Quarkus.
In this project I've got a DAO which is shared by many EJB's (SOAP services, REST services). The DAO defines also the entities and the persistence.xml like this:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="broGmw">
<jta-data-source>java:jboss/datasources/BroDS</jta-data-source>
<class>x</class>
<class>y</class>
<!--> many more <-->
<properties>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
Now, I know that the jta datasource is not yet supported in quarkus.
I don't want to redefine the same persistence.xml in each endpoint EJB in my JEE project. Also, removing it from the DAO library does not feel logical, since persistence.xml logically belongs to the DAO.
Quarkus however, does not tolerate the jta-data-source. So I want to redefine only the data-source in the application properties, leaving the persistence.xml in the DAO (library).
quarkus.datasource.broDs.db-kind=other
quarkus.datasource.broDs.username=xxx
quarkus.datasource.broDs.password=yyy
quarkus.datasource.broDs.jdbc.url=myUrl
quarkus.datasource.broDs.jdbc.driver=${QUARKUS-BRO-DATASOURCE-DRIVER:oracle.jdbc.OracleDriver}
quarkus.hibernate-orm.broGmw.dialect=${QUARKUS-ORM-DIALECT:org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect}
quarkus.hibernate-orm.broGmw.log.sql=${QUARKUS-ORM-LOG-SQL:false}
#quarkus.hibernate-orm.broGmw.packages=... (here's where I want the content of my persistence.xml read)
quarkus.hibernate-orm.broGmw.datasource=broDs
However, Quarkus ignores this as soon when it finds the persistence.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:00 min
[INFO] Finished at: 2021-01-14T22:28:38+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.10.5.Final:build (default) on project gmw_rest_dispatch: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#build threw an exception: java.lang.UnsupportedOperationException: Value found for #getJtaDataSource : not supported yet
[ERROR] at io.quarkus.hibernate.orm.runtime.boot.LightPersistenceXmlDescriptor.verifyIgnoredFields(LightPersistenceXmlDescriptor.java:164)
[ERROR] at io.quarkus.hibernate.orm.runtime.boot.LightPersistenceXmlDescriptor.validateAndReadFrom(LightPersistenceXmlDescriptor.java:55)
[ERROR] at io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDefinition.<init>(QuarkusPersistenceUnitDefinition.java:34)
How can I realize this?
Filtering the persistence.xml from the dependencies is perhaps also an option. I know that this is possible in the next version of Quarkus, but perhaps there's a generic mechanism to filter files (classes, xml) from the dependencies to make Quarkus ignore them.
The SKIP_PARSE_PERSISTENCE_XML property has to be passed when you run your Quarkus application, not when you build it.
Passing it to the quarkus-maven-plugin won't help.
It requires to be added to the maven build as -D property, configured in the IDE and in possible build scripts in CI/CD.

Hibernate: no persistent classes found for query class but mapping is correct

This question has been asked many times, but I have not encountered a solution for my problem as on first sight everything seems right. It is a configuration problem when using this Hibernate setup:
hibernate-core: 5.2.11.Final
hibernate-jpa-2.1-api: 1.0.0.Final
hibernate-commons-annotations: 5.0.1.Final
When I try to execute a query I get a warning in the console that says no persistent classes found for query class but no error is thrown, and no data is retrieved from database although it should return over 30 entries.
09:56:58,203 INFO [org.hibernate.Version] (default task-46) HHH000412: Hibernate Core {5.2.11.Final}
09:56:58,206 INFO [org.hibernate.cfg.Environment] (default task-46) HHH000206: hibernate.properties not found
09:56:58,348 INFO [org.hibernate.annotations.common.Version] (default task-46) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
09:56:58,397 WARN [org.hibernate.orm.connections.pooling] (default task-46) HHH10001002: Using Hibernate built-in connection pool (not for production use!)
09:56:58,398 INFO [org.hibernate.orm.connections.pooling] (default task-46) HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/db_motor?useSSL=false&autoReconnect=true]
09:56:58,398 INFO [org.hibernate.orm.connections.pooling] (default task-46) HHH10001001: Connection properties: {user=admin, password=****}
09:56:58,398 INFO [org.hibernate.orm.connections.pooling] (default task-46) HHH10001003: Autocommit mode: false
09:56:58,400 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (default task-46) HHH000115: Hibernate connection pool size: 10 (min=1)
09:56:58,647 INFO [org.hibernate.dialect.Dialect] (default task-46) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
09:56:58,958 WARN [org.hibernate.hql.internal.QuerySplitter] (default task-46) HHH000183: no persistent classes found for query class: SELECT respuestas FROM mr.hibernate.beans.MR_RespuestasHBean respuestas
09:56:58,959 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (default task-46) HHH000397: Using ASTQueryTranslatorFactory
It seems the warning about hibernate.properties not found is not of any influence if I interpret information found on this website correctly.
The hibernate.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="session_factory">
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.password">admin</property>
<property name="connection.pool_size">10</property> <!-- not for production -->
<property name="connection.url">jdbc:mysql://localhost:3306/db_motor?useSSL=false&autoReconnect=true</property>
<property name="connection.username">admin</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping class="mr.hibernate.beans.MR_RespuestasHBean"/>
</session-factory>
</hibernate-configuration>
The mapped class:
package mr.hibernate.beans;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "t_respuestas")
public class MR_RespuestasHBean implements Serializable {
private static final long serialVersionUID = 3892055031093758454L;
#Id
#Column(name = "COD_RESPUESTA", nullable = false, length = 11)
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long codigoRespuesta;
public Long getCodigoRespuesta() {
return codigoRespuesta;
}
public void setCodigoRespuesta(Long codigoRespuesta) {
this.codigoRespuesta = codigoRespuesta;
}
}
Table definition:
CREATE TABLE t_respuestas
(
COD_RESPUESTA int PRIMARY KEY NOT NULL
)
;
CREATE UNIQUE INDEX PRIMARY ON t_respuestas(COD_RESPUESTA)
;
The code used to get the query is this:
session = getSession(HibernateUtil.configurationFileMySql);
session.beginTransaction();
StringBuffer hql = new StringBuffer();
StringBuffer select = new StringBuffer();
select.append("SELECT respuestas");
StringBuffer from = new StringBuffer();
from.append(" FROM "+ MR_RespuestasHBean.class.getName() +" respuestas");
hql.append(select);
hql.append(from);
#SuppressWarnings("unchecked")
Query<MR_RespuestasHBean> query = session.createQuery(hql.toString());
listado = query.list();
If I change MR_RespuestasHBean.class.getName() by MR_RespuestasHBean.class.getSimpleName(), an error is thrown:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: MR_RespuestasHBean is not mapped
Some information on the environment:
JBoss EAP7
JDK8
MySql connector 6.0.6
The Hibernate part is in an EJB3 project
However, when using this setup, everything works well (logically, session loading and query execution has to be different):
hibernate-core: 4.2.0.Final
hibernate-jpa-2.0-api: 1.0.1.Final
hibernate-commons-annotations: 4.0.1.Final
Any clues on what is causing the problem is very much appreciated.

No database connection after deployment (Java Hibernate)

I am creating an app for school that generates business rules.
The front end consists of Apex and the backend is a java application that uses hibernate to access the database.
To communicate between Apex and Java I am using a rest service (using struts2).
This works fine when I deploy the application in my IDE (netbeans). But then it runs on my localhost. This way the Apex application can not connect to it. (The Apex application is hosted by my school)
So I tried deploying my application using various websites. The rest service part still works and I can connect the java app with my Apex application.
The problem is that the java application cant seem to connect to the database as soon as i deploy it online.
The glassfish console shows this when I try to get data from the database:
(Tosad is the name of the project/course)
[2016-01-08T15:23:07.004+0000] [glassfish 4.1] [INFO] [] []
[tid: _ThreadID=43 _ThreadName=Thread-8] [timeMillis: 1452266587004] [levelValue: 800] [[
[EL Severe]: ejb: 2016-01-08 15:23:07.004--ServerSession(1585495182)--
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [TOSAD].
Internal Exception: javax.naming.NamingException: Lookup failed for 'TOSAD' in SerialContext[
myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
java.naming.factory.url.pkgs=com.sun.enterprise.naming}
[Root exception is javax.naming.NameNotFoundException: TOSAD not found]]]
Hibernate.cfg.xml (I replaced some info for safety purposes)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#ondora02.hu.nl:PORT:COURSE</property>
<property name="hibernate.connection.username">USERNAME</property>
<property name="hibernate.connection.password">PASSWORD</property>
</session-factory>
</hibernate-configuration>
HibernateUtil.java
package Service;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class HibernateUtil {
private static String orclcfg = "nl.hu.ict.jpa.oracle";
private static String mysqlcfg = "nl.hu.ict.jpa.mysql";
private static boolean mysql = false;
private static String dbcfg = orclcfg;
private static final EntityManagerFactory entityManagerFactory;
//entityManagerFactory = Persistence.createEntityManagerFactory("nl.hu.ict.jpa.oracle" );
static {
try {
if (!mysql) {
dbcfg = orclcfg;
}
entityManagerFactory = Persistence.createEntityManagerFactory(dbcfg);
} catch (Throwable th) {
System.err.println("Initial EntityManagerFactory creation failed" + th);
throw new ExceptionInInitializerError(th);
}
}
public static EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
}
The error message is somewhat clear. The JNDI resource named TOSAD cannot be located on your remote deployed server. Make sure it is configured on the remote server like you likely have done on your local machine.

configuring hyperjaxb to create hibernate mappings and a mysql database

I am using hyperjaxb to generate Java classes from an xsd file. How can I configure it to generate hibernate annotations, and to trigger hbm2ddl to create a MySQL database with tables for the generated classes?
I downloaded the purchase order sample for hibernate from this link, then navigated to the target directory in cmd.exe and ran mvn clean install, but the resulting folders did not contain any java classes, and this also did not contain any hibernate/MySQL. I would like to get a working example that creates everything from a downloaded xsd file so that I can just plug my own xsd file into the code and have all the java/hibernate/mysql be autogenerated. That way I can spend my time tweaking my xsd file so that the resulting java/hibernate/MySQL is what I need it to be.
A code example or step by step instructions would be really helpful. I am using eclipse.
**EDIT: **
The answer to this question came after posting a few other questions. To find the complete answer to this question, you will need to review the answers to those other questions, in particular, the one at this link.
UPDATE
Finally it appeared that the OP was looking for generated classes in the root directory of the project insteadof target\generated-source\xjc, despite the tutorial clearly states where to look:
If you browse the target/generated-sources/xjc directory, you'll find
few generated java files, for instance PurchaseOrderType.java.
I don't understand it when you say that nothing is generated. I've just rechecked it, everything works fine.
My steps are:
Download hyperjaxb3-ejb-samples-po-initial-0.5.6-maven-src.zip
Unzip
Go to hyperjaxb3-ejb-samples-po-initial-0.5.6
mvn clean install
Here's what I get:
[INFO] ------------------------------------------------------------------------
[INFO] Building Hyperjaxb3 Samples [po-initial:maven] 0.5.6
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Deleting C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target
[INFO]
[INFO] --- maven-hyperjaxb3-plugin:0.6.0:generate (default) # hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Sources are not up-to-date; XJC execution will be executed.
[WARNING] According to the Java Persistence API specification, section 2.1, entities must be top-level classes:
"The entity class must be a top-level class."
Your JAXB model is not customized as with top-level local scoping, please use the <jaxb:globalBinding localScoping="toplevel"/> global bindings customization.
org.jvnet.hyperjaxb3.ejb.plugin.EjbPlugin
[WARNING] According to the Java Persistence API specification, section 2.1, entities must implement the serializable interface:
"If an entity instance is to be passed by value as a detached object
(e.g., through a remote interface), the entity class must implement
the Serializable interface."
Your JAXB model is not customized as serializable, please use the <jaxb:serializable/> global bindings customization element to make your model serializable.
org.jvnet.hyperjaxb3.ejb.plugin.EjbPlugin
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 5 source files to C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # hyperjaxb3-ejb-samples-po-initial-maven ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 5 source files to C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Surefire report directory: C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running RoundtripTest
Detected [file:/C:/Projects/workspaces/hj3/dist/hyperjaxb3-ejb-samples-po-initial-0.5.6/target/classes/META-INF/persistence.xml].
RoundtripTest
Loading entity manager factory properties.
RoundtripTest
Loading entity manager factory properties from [file:/C:/Projects/workspaces/hj3/dist/hyperjaxb3-ejb-samples-po-initial-0.5.6/target/test-classes/persistence.properties].
RoundtripTest
Testing samples.
RoundtripTest
Sample directory [C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\src\test\samples].
RoundtripTest
Testing sample [po.xml].
RoundtripTest
Unmarshalling.
RoundtripTest
Opening session.
RoundtripTest
Saving the object.
RoundtripTest
Opening session.
RoundtripTest
Loading the object.
RoundtripTest
Closing the session.
RoundtripTest
Initial object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>
RoundtripTest
Source object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20" Hjid="1">
<shipTo country="US" Hjid="2">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US" Hjid="1">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items Hjid="1">
<item partNum="872-AA" Hjid="1">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA" Hjid="2">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>
RoundtripTest
Result object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20" Hjid="1">
<shipTo country="US" Hjid="2">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US" Hjid="1">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items Hjid="1">
<item partNum="872-AA" Hjid="1">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA" Hjid="2">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>
RoundtripTest
Checking the document identity.
RoundtripTest
Finished testing sample [po.xml].
RoundtripTest
Finished testing samples.
RoundtripTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.552 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Building jar: C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # hyperjaxb3-ejb-samples-po-initial-maven ---
[INFO] Installing C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\target\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.jar to C:\Repository\org\jvnet\hyperjaxb3\hyperjaxb3-ejb-samples-po-initial-maven\0.5.6\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.jar
[INFO] Installing C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-samples-po-initial-0.5.6\pom.xml to C:\Repository\org\jvnet\hyperjaxb3\hyperjaxb3-ejb-samples-po-initial-maven\0.5.6\hyperjaxb3-ejb-samples-po-initial-maven-0.5.6.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.100 s
[INFO] Finished at: 2014-10-09T00:42:10+01:00
[INFO] Final Memory: 22M/96M
[INFO] ------------------------------------------------------------------------
Full mvn clean install -X log is here.
So I hope you see, it works perfectly. Please post you mvn clean install -X, maybe you do something wrong.
Now, concerning your question, here's the MySQL example:
https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/po-mysql
This project includes a snippet of hbm2ddl generation:
https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/issues
The hbm2ddl is commented out for some reason, not sure if it works, but it should give the direction.
This is a part of another answer which answers the MySQL part. I add this here for future reference in an attempt to close this question.
So from now on I assume that the PO tutorial worked fine: the code was generated, roundtrip test ran with the HSQLDB database etc.
Now we'll address two questions:
How to switch to MySQL?
How to generate database schema with hbm2ddl?
Let's get started.
Switching to MySQL
First of all, you have to replace HSQLDB with MySQL in the pom.xml. Remove this:
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
<scope>test</scope>
</dependency>
And add this:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
<scope>test</scope>
</dependency>
Next, edit src/test/resources/persistence.properties. Replace this:
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.url=jdbc:hsqldb:target/test-database/database
hibernate.hbm2ddl.auto=create-drop
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
hibernate.jdbc.batch_size=0
With this:
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.username=...
hibernate.connection.password=...
hibernate.connection.url=jdbc:mysql://localhost/hj3
hibernate.hbm2ddl.auto=create-drop
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
hibernate.jdbc.batch_size=0
I personally don't have a MySQL database at hand at the moment, so I can't really test the roundtrip. Therefore I'll comment out
<!--roundtripTestClassName>RoundtripTest</roundtripTestClassName-->
in pom.xml.
If you have a database at hand, just configure the right URL/username/password in the mentioned persistence.properties file.
At this point your Maven project is reconfigured to use MySQL. If the roundtrip test is not commented out and the database is available, the roundrip test should run with the DB, i.e. create the schema, import the sample XML, read it back and compare alpha and omega.
So now we have the tutorial on MySQL and can move on.
Generating the database schema
This was a tricky part to figure out.
In order to generate the database schema in a file, you have to use the hbm2ddl tool. There are Maven plugins for that, in case of Hibernate 3 it seemed that the Codehaus plugin is the leading one. Finally, I have figured out the following configuration. You have to add the following plugin to your pom.xml (project/build/plugins):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>generate-schema</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<hibernatetool>
<classpath>
<path location="${project.build.directory}/classes" />
</classpath>
<jpaconfiguration persistenceunit="org.jvnet.hyperjaxb3.ejb.tests.pocustomized" propertyfile="src/test/resources/persistence.properties"/>
<hbm2ddl export="false" create="true" update="false" format="true" outputfilename="schema.ddl" />
</hibernatetool>
</configuration>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.5.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
</dependency>
</dependencies>
</plugin>
Few things are important:
Hyperjaxb3 generates JPA annotations, so you have to use jpaconfiguration.
Therefore the hibernate3-maven-plugin must be executed in the compile phase (you need classes to read annotations from so they have to be compiled at that moment).
You have to include the compiled classes (${project.build.directory}/classes) to the hibernatetool's classpath so that it can discover classes and read annotations.
You have to let the hibernatetool know where you find your Hibernate properties (propertyfile="src/test/resources/persistence.properties").
Finally you have to let it know, which persistence unit you want to process (persistenceunit="org.jvnet.hyperjaxb3.ejb.tests.pocustomized"). Take a look at target/generated-sources/xjc/META-INF/persistence.xml.
Finally, add all the required dependencies.
Finally you arrive at the configuration I posted above. At this point the build should also generate the database schema in target/sql/hibernate3/schema.ddl.

Hibernate does not commit data

I'm trying to write a web service to store some data using jBoss 4.2.3 and Oracle.
I suppose to use Hibernate with CMT and seems to me it doesn't commit the transaction.
I have the following code:
Bean:
#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;
}
}
Interface:
#Local
public interface ZzzI {
int addZzz();
}
My session factory class:
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;
}
}
hibernate.cfg.xml has following:
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#//my_host</property>
<property name="hibernate.connection.username">my_user</property>
<property name="hibernate.connection.password">my_pass</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">jta</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<mapping resource="com/example/Zzz.hbm.xml" />
</session-factory>
Mapping file:
<hibernate-mapping>
<class name="com.example.Zzz" table="ZZZ">
<id name="i" type="big_decimal">
<column name="i" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="a" type="string">
<column name="a" length="20" />
</property>
</class>
</hibernate-mapping>
Entity class:
#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;
}
}
And the web service 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();
}
}
When I call web service method I have the following output:
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 -> 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 (?, ?)
But database does not have a new record even when I stop jBoss. Where is my fault? Please help.
P.S. When I am not using CMT and write code like:
tx = session.beginTransaction();
session.persist(...);
tx.commit();
all works fine.
I have found a solution: I moved database connection configuration from hibernate.cfg.xml to datasource (Z-ds.xml) and it works now. Of course this is not a normal solution of a problem, but a workaround. Thanks to all!

Categories