-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate tries to load fields in wrong order.
PostPosted: Fri Nov 09, 2012 11:37 am 
Newbie

Joined: Fri Nov 09, 2012 10:43 am
Posts: 1
General info:
Eclipse Juno. JBoss 7.1. PostgreSQL 9.2. Driver: postgresql-9.1-901-1.jdbc4.jar (there is no newer version in repository, should work anyway). Hibernate (according to maven dependencies and pom.xml): validator 4.2.0.Final, jpamodelgen 1.1.1.Final, jpa2 1.0.1.Final.

Problem:
Hibernate tries to load fields from table in wrong order. This throws exception.

Reproduction:
After creating simple project (based on artifact richfaces-archetype-kitchensink) called testproject, add to pom.xml:
Code:
<dependencies>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
        <scope>compile</scope>
    </dependency>
    ...
</dependencies>

Create entity in model package:
Code:
@Entity
@Table(name = "test_entity")
public class TestEntity implements Serializable
{
  /** Default value included to remove warning. */
  private static final long serialVersionUID = 1L;

  /** Obligatory unique identificator in table. */
  @Id
  private Long    id;

  /** Name of entry. */
  @NotNull
  @Size(max = 75)
  private String  name;

  /** Queue of entry. Allow to show entries in arbitrary order. */
  @NotNull
  private Integer queue;

  /** Description of entry for developer. */
  @Lob
  private String  descr;

  // ... just getters and setters, nothing fancy here
}

import.sql:
Code:
INSERT INTO test_entity(id, name, queue, descr) VALUES (1, 'One', 666, 'elemelek');
INSERT INTO test_entity(id, name, queue, descr) VALUES (2, 'Two', 13, '03958439504');
INSERT INTO test_entity(id, name, queue, descr) VALUES (3, 'Three', 0, 'b u r n');

And simple bean that will try to load entries:
Code:
@ManagedBean(eager = true)
@ApplicationScoped
public class TestMng
{
  @Inject
  private Logger        log;
  @Inject
  private EntityManager em;

  public void reloadTest()
  {
    log.info("Loading test ultrasimple entity...");
   
    String qStr = "select t from TestEntity t\n";
    TypedQuery<TestEntity> query = em.createQuery(qStr, TestEntity.class);
    List<TestEntity> tests = query.getResultList();
   
    log.info("Loading test ultrasimple entity successful! Count: " + tests.size());
  }
}

Of course, you need to configure persistence.xml...
Code:
<?xml version="1.0" encoding="UTF-8"?>
<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="primary">
    <!-- The datasource is deployed as src/main/webapp/WEB-INF/testproject-ds.xml -->
    <jta-data-source>java:jboss/datasources/PostgreSqlDS</jta-data-source>
    <properties>
      <!-- Properties for Hibernate -->
      <property name="hibernate.hbm2ddl.auto" value="create-drop" />
      <property name="hibernate.show_sql" value="true" />
    </properties>
  </persistence-unit>
</persistence>

...and testproject-ds.xml too.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
  <!-- The datasource is bound into JNDI at this location. We reference this in META-INF/persistence.xml -->
  <datasource jndi-name="java:jboss/datasources/PostgreSqlDS" pool-name="PostgreSqlDS" enabled="true"
    use-java-context="true">
    <connection-url>jdbc:postgresql://localhost:5432/testprojectdb</connection-url>
    <driver>postgresql</driver>
    <pool>
      <min-pool-size>10</min-pool-size>
      <max-pool-size>100</max-pool-size>
      <prefill>true</prefill>
    </pool>
    <security>
      <user-name>test</user-name>
      <password>test</password>
    </security>
  </datasource>
</datasources>

After starting JBoss here is revelant SQL snippet:
Quote:
15:08:50,824 INFO [stdout] (MSC service thread 1-7) Hibernate: create table test_entity (id int8 not null, descr text, name varchar(75) not null, queue int4 not null, primary key (id))

After calling reloadTest() (I simply used <f:event type="preRenderView" listener="#{testMng.reloadTest()}"/> in <f:metadata>) this happens:
Quote:
15:10:30,071 INFO [org.mader.TestMng] (http-localhost-127.0.0.1-8080-1) Loading test ultrasimple entity...
15:10:30,449 INFO [stdout] (http-localhost-127.0.0.1-8080-1) Hibernate: select testentity0_.id as id6_, testentity0_.descr as descr6_, testentity0_.name as name6_, testentity0_.queue as queue6_ from test_entity testentity0_

15:10:30,497 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) SQL Error: 0, SQLState: 22003
15:10:30,497 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) Wrong value for type long: elemelek
15:10:30,497 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/testproject].[FacesServlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet FacesServlet threw exception: org.postgresql.util.PSQLException: Wrong value for type long: elemelek
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2971) [postgresql-9.1-901-1.jdbc4.jar:]
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2163) [postgresql-9.1-901-1.jdbc4.jar:]
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob(AbstractJdbc2ResultSet.java:436) [postgresql-9.1-901-1.jdbc4.jar:]
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob(AbstractJdbc2ResultSet.java:424) [postgresql-9.1-901-1.jdbc4.jar:]
at org.jboss.jca.adapters.jdbc.WrappedResultSet.getClob(WrappedResultSet.java:783)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0]
at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at $Proxy74.getClob(Unknown Source) at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$4.doExtract(ClobTypeDescriptor.java:108) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2695) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1552) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1484) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.getRow(Loader.java:1384) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:856) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2463) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2449) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.list(Loader.java:2274) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1115) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.jboss.as.jpa.container.TypedQueryNonTxInvocationDetacher.getResultList(TypedQueryNonTxInvocationDetacher.java:58) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.mader.TestMng.reloadTest(TestMng.java:55) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0]
at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2486) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2168) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2116) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:288) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:246) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.jboss.as.weld.webtier.jsf.ForwardingApplication.publishEvent(ForwardingApplication.java:293) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:172) [rewrite-servlet-1.0.4.Final.jar:1.0.4.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0]

It looks like Hibernate tries to put value of descr field into id field. If you remove descr field from entity, everything works. Of course, this renders Hibernate completely useless.

My question is obvious: what to do with this? I have no printable words for this, frankly speaking.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.