Hi y'all I've been trying to get a simple application to work with hibernate but it keeps failing without a clue of why it does so.
Basing on GWT sample application:
Code:
package com.mircom.spring.server;
import com.mircom.spring.client.GreetingService;
import com.mircom.spring.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
// import org.springframework.context.support.ClassPathXmlApplicationContext;
// import org.springframework.context.ApplicationContext;
import org.hibernate.Session;
// import org.hibernate.Transaction;
// import org.hibernate.HibernateException;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
public String greetServer(String input) throws IllegalArgumentException {
// Verify that the input is valid.
if (!FieldVerifier.isValidName(input)) {
// If the input is not valid, throw an IllegalArgumentException back to
// the client.
throw new IllegalArgumentException(
"Name must be at least 4 characters long");
}
// Escape data from the client to avoid cross-site script vulnerabilities.
input = escapeHtml(input);
Session session = (Session) SessionManager.getSession();
// Transaction tx = session.beginTransaction();
// CHECK IF SESSION IS NULL
Articulo articulo = (Articulo) session.get(Articulo.class, 1);
String ret = "ARTICULO=" + articulo.getDescripcion();
// System.out.println(ret);
// tx.commit();
// session.close();
return ret;
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&").replaceAll("<", "<")
.replaceAll(">", ">");
}
}
Articulo class:
Code:
package com.mircom.spring.server;
import java.util.Currency;
import java.io.Serializable;
/* If the persistent objects are distributed over the network,
* or are stored in an HttpSession, they must implement the
* java.io.Serializable interface.
*/
public class Articulo implements Serializable {
/**
* serialVersionUID necesario para Serializable
*/
private static final long serialVersionUID = 1L;
private int id;
private String codigo;
private String descripcion;
private Currency precioCompra;
private Currency precioVenta;
private int idUdMedida;
private String descripcionLarga;
private String tipoArticulo;
//zero-argument constructor
public Articulo() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public Currency getPrecioCompra() {
return precioCompra;
}
public void setPrecioCompra(Currency precioCompra) {
this.precioCompra = precioCompra;
}
public Currency getPrecioVenta() {
return precioVenta;
}
public void setPrecioVenta(Currency precioVenta) {
this.precioVenta = precioVenta;
}
public int getIdUdMedida() {
return idUdMedida;
}
public void setIdUdMedida(int idUdMedida) {
this.idUdMedida = idUdMedida;
}
public String getCodigo() {
return codigo;
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getDescripcionLarga() {
return descripcionLarga;
}
public void setDescripcionLarga(String descripcionLarga) {
this.descripcionLarga = descripcionLarga;
}
public String getTipoArticulo() {
return tipoArticulo;
}
public void setTipoArticulo(String tipoArticulo) {
this.tipoArticulo = tipoArticulo;
}
public String toString(){
return id+":"+descripcion+":"+idUdMedida+":"+precioCompra+":"+precioVenta;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Articulo articulo = (Articulo) o;
if (id != articulo.id) return false;
if (descripcion != null ? !descripcion.equals(articulo.descripcion) :
articulo.descripcion != null) return false;
return true;
}
public int hashCode() {
int result;
result = id;
result = 29 * result + (descripcion != null ? descripcion.hashCode(): 0);
return result;
}
Being hibernate config:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- database related configurations -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/signing</property>
<property name="connection.username">root</property>
<property name="connection.password">ressec</property>
<property name="pool_size">5</property> <!-- specifies the number of connection objects held in the connection pool -->
<property name="connection.autocommit">true</property> <!-- Si no se controla manualmente -->
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- mapping files-->
<mapping
resource="com/mircom/spring/server/Articulo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Articulo.hbm.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.mircom.spring.server.Articulo" table="articulos">
<id name="id" type="integer" column="idarticulo">
<generator class="identity"/>
</id>
<!--
<discriminator column="tipo_articulo" type="string"/>
-->
<property name="tipoArticulo" column="tipo_articulo" type="string" />
<property name="codigo" column="codigo" type="string" />
<property name="descripcion" column="descripcion" type="string" />
<property name="precioCompra" column="precio_compra" type="currency" />
<property name="precioVenta" column="precio_venta" type="currency" />
<property name="idUdMedida" column="id_ud_medida" type="integer" />
<property name="descripcionLarga" column="descripcion_larga" type="string" />
<!--
<subclass name="com.mircom.spring.server.Articulo_Senalizacion_Horizontal" discriminator-value="0" />
<subclass name="com.mircom.spring.server.Articulo_Senalizacion_Vertical" discriminator-value="1" />
-->
</class>
</hibernate-mapping>
Console output is:
Code:
267 [btpool0-2] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
308 [btpool0-2] INFO org.hibernate.cfg.Environment - Hibernate 3.6.9.Final
312 [btpool0-2] INFO org.hibernate.cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.c3p0.timeout=1800, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.c3p0.max_statements=50, hibernate.dialect=org.hibernate.dialect.MySQL5Dialect, hibernate.c3p0.max_size=20, hibernate.c3p0.min_size=5, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://localhost:3306/signing, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****}
341 [btpool0-2] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
346 [btpool0-2] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
634 [btpool0-2] INFO org.hibernate.cfg.Configuration - configuring from resource: com/mircom/spring/server/hibernate.cfg.xml
634 [btpool0-2] INFO org.hibernate.cfg.Configuration - Configuration resource: com/mircom/spring/server/hibernate.cfg.xml
1252 [btpool0-2] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : com/mircom/spring/server/Articulo.hbm.xml
2031 [btpool0-2] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
2251 [btpool0-2] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.mircom.spring.server.Articulo -> articulos
2327 [btpool0-2] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
2407 [btpool0-2] INFO org.hibernate.validator.util.Version - Hibernate Validator 4.2.0.Final
2660 [btpool0-2] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
2670 [btpool0-2] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider
2671 [btpool0-2] INFO org.hibernate.connection.C3P0ConnectionProvider - C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/signing
2671 [btpool0-2] INFO org.hibernate.connection.C3P0ConnectionProvider - Connection properties: {user=root, password=****, autocommit=true}
2671 [btpool0-2] INFO org.hibernate.connection.C3P0ConnectionProvider - autocommit mode: true
12:18:58,736 INFO MLog:80 - MLog clients using log4j logging.
12:18:59,605 INFO C3P0Registry:204 - Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
12:18:59,753 INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@250a87a6 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@8a9c5654 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2vltzl8k125w4li1vpygie|12b520a, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@814009aa [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2vltzl8k125w4li1vpygie|1935a68, jdbcUrl -> jdbc:mysql://localhost:3306/signing, properties -> {user=******, password=******, autocommit=true} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2vltzl8k125w4li1vpygie|67178f, numHelperThreads -> 3 ]
5308 [btpool0-2] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQL5Dialect
5394 [btpool0-2] INFO org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
5394 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Database ->
name : MySQL
version : 5.5.16
major : 5
minor : 5
5394 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Driver ->
name : MySQL-AB JDBC Driver
version : mysql-connector-java-5.1.18 ( Revision: tonci.grgin@oracle.com-20110930151701-jfj14ddfq48ifkfq )
major : 5
minor : 1
5426 [btpool0-2] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
5429 [btpool0-2] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
5429 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
5429 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
5430 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
5441 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
5443 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
5443 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
5443 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
5458 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
5459 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
5459 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
5459 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
5459 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
5459 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
5476 [btpool0-2] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
5476 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
5476 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
5476 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
5476 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
5477 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
5483 [btpool0-2] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
5484 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
5484 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
5507 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
5508 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
5508 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
5508 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
5508 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
5508 [btpool0-2] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): disabled
5543 [btpool0-2] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@e5fc61
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.ClobType@11c627c
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@11c627c
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@85e47e
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@5c1bd9
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@1287915
5585 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@1287915
5586 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@258ed1
5586 [btpool0-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@1c33c70
6250 [btpool0-2] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
Hibernate: select articulo0_.idarticulo as idarticulo0_0_, articulo0_.tipo_articulo as tipo2_0_0_, articulo0_.codigo as codigo0_0_, articulo0_.descripcion as descripc4_0_0_, articulo0_.precio_compra as precio5_0_0_, articulo0_.precio_venta as precio6_0_0_, articulo0_.id_ud_medida as id7_0_0_, articulo0_.descripcion_larga as descripc8_0_0_ from articulos articulo0_ where articulo0_.idarticulo=?
So it seems to work, but it doesnt, and returns control to:
Code:
greetingService.greetServer(textToServer,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
dialogBox
.setText("Remote Procedure Call - Failure");
serverResponseLabel
.addStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(SERVER_ERROR);
dialogBox.center();
closeButton.setFocus(true);
}
public void onSuccess(String result) {
dialogBox.setText("Remote Procedure Call");
serverResponseLabel
.removeStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(result);
dialogBox.center();
closeButton.setFocus(true);
}
});
As an error. This last code is an exerpt of GWT generated sample code.
My libraries in classpath are:
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-jar
hibernate3.jar
log4j-1.2.16.jar
mysql-connector-java-5.1.18-bin.jar
c3p0-0.9.1.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-4.2.0.Final.jar
hibernate-validator-annotation-processor-4.2.0.Final.jar
validation-api-1.0.0.GA.jar
slf4j-simple-1.6.1.jar
I get the feeling it could be a library version incompatibility
¿Can anyone help?
BTW, log file content is:
Code:
12:18:58,736 INFO MLog:80 - MLog clients using log4j logging.
12:18:59,605 INFO C3P0Registry:204 - Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
12:18:59,753 INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@250a87a6 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@8a9c5654 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2vltzl8k125w4li1vpygie|12b520a, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@814009aa [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2vltzl8k125w4li1vpygie|1935a68, jdbcUrl -> jdbc:mysql://localhost:3306/signing, properties -> {user=******, password=******, autocommit=true} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2vltzl8k125w4li1vpygie|67178f, numHelperThreads -> 3 ]