-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate 5.1.0 with mysql "Text" field error
PostPosted: Tue Apr 26, 2016 12:10 am 
Newbie

Joined: Tue Apr 26, 2016 12:06 am
Posts: 3
Hi
I am using Hibernate 5.1.0 with mysql "Text" feild, i map the field without any annotation, just "String raw". I am find to insert record but when i select records by hql, it got error. If i change the file type to "varcher(255)", everything fine but i have to use the type "Text" for long string.

Code:
[ERROR] [04:08:14] [SqlExceptionHelper.java:131]    An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 6
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
   at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
   at org.hibernate.loader.Loader.doList(Loader.java:2613)
   at org.hibernate.loader.Loader.doList(Loader.java:2593)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
   at org.hibernate.loader.Loader.list(Loader.java:2417)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
   at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
   at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
   at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
   at com.st.HibernateUtil.main(HibernateUtil.java:33)
Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 6
   at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
   at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
   at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:74)
   at com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable(NewPooledConnection.java:492)
   at com.mchange.v2.c3p0.impl.NewProxyResultSet.getBoolean(NewProxyResultSet.java:2284)
   at org.hibernate.type.descriptor.sql.BooleanTypeDescriptor$2.doExtract(BooleanTypeDescriptor.java:59)
   at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:235)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:231)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:222)
   at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:296)
   at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2762)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1728)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1654)
   at org.hibernate.loader.Loader.getRow(Loader.java:1543)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727)
   at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
   at org.hibernate.loader.Loader.doQuery(Loader.java:930)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
   at org.hibernate.loader.Loader.doList(Loader.java:2610)
   ... 9 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
   at com.mysql.cj.mysqla.MysqlaUtils.bitToLong(MysqlaUtils.java:68)
   at com.mysql.cj.core.io.MysqlTextValueDecoder.decodeBit(MysqlTextValueDecoder.java:231)
   at com.mysql.cj.jdbc.ResultSetRow.decodeAndCreateReturnValue(ResultSetRow.java:170)
   at com.mysql.cj.jdbc.ResultSetRow.getValueFromBytes(ResultSetRow.java:269)
   at com.mysql.cj.jdbc.BufferRow.getValue(BufferRow.java:349)
   at com.mysql.cj.jdbc.ResultSetImpl.getNonStringValueFromRow(ResultSetImpl.java:813)
   at com.mysql.cj.jdbc.ResultSetImpl.getBoolean(ResultSetImpl.java:904)
   at com.mysql.cj.jdbc.ResultSetImpl.getBoolean(ResultSetImpl.java:908)
   at com.mchange.v2.c3p0.impl.NewProxyResultSet.getBoolean(NewProxyResultSet.java:2270)
   ... 24 more



thanks
from Peter


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1.0 with mysql "Text" field error
PostPosted: Tue Apr 26, 2016 1:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Try adding a @Column mapping like this:

Code:
@Column(name="my_field", columnDefinition="text")
@Type(type = "text")
private String myProperty;


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1.0 with mysql "Text" field error
PostPosted: Tue Apr 26, 2016 11:29 am 
Newbie

Joined: Tue Apr 26, 2016 12:06 am
Posts: 3
thanks mihalcea_vlad, but not working, here is my mapping class:

Code:
@Entity
@Table(name = "tradeOrder")
public class TradeOrder {
   @Id
   @GeneratedValue(strategy = IDENTITY)
   @Column(name = "id", unique = true, nullable = false)
   public Integer id;

   public String orderNo;
   public Date createTime;
   public Date updatedTime;
   public float price;
   public int qty;
   public String productNo;
   public boolean isBid;
   public String branch;
   public String username;

   @Column(name="raw", columnDefinition="text")
   @Type(type = "text")
   public String raw;

   public String toString() {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
      return orderNo + " - " + productNo + " - " + price + " - " + qty + " - " + sdf.format(createTime) + " - " + sdf.format(updatedTime);
   }
}


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1.0 with mysql "Text" field error
PostPosted: Wed Apr 27, 2016 2:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
The mapping works. You can check out and run out this test on GitHub.

The mapping looks like this:

Code:
@Entity(name = "Event")
@Table(name = "event")
public static class Event {

    @Id
    @GeneratedValue
    private Long id;

    @Column(name="my_field", columnDefinition="text")
    @Type(type = "text")
    private String message;
}


The generated table is:

Code:
create table event (id bigint not null, my_field text, primary key (id))


When inserting a long String:

Code:
Event event = new Event();
char[] chars = new char[1000];
Arrays.fill(chars, 'a');
event.message = new String(chars);
entityManager.persist(event);


Hibernate inserts it just fine as a TEXT:

Code:
DEBUG [main]: n.t.d.l.SLF4JQueryLoggingListener - Name:DATA_SOURCE_PROXY, Time:1, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["insert into event (my_field, id) values (?, ?)"], Params:[(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 2)]


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

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.