-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with Column Type using Hibernate: Wrong datatype us
PostPosted: Tue Sep 14, 2004 12:35 am 
Newbie

Joined: Tue Sep 14, 2004 12:05 am
Posts: 5
I'm running into a problem where it appears that a column that I intend to map as a String is being read in as a Byte. Apologies in advance if I've provided too much information below, let me know the right amount and I'll adjust in the future. M
Hibernate version: 2.1.6

Mapping documents:
Code:
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE hibernate-mapping PUBLIC
       "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   <hibernate-mapping
   >
       <class
      name="com.iss.va.vo.impl.SecurityIndex"
      table="securityindex"
      dynamic-update="false"
      dynamic-insert="false"
      select-before-update="false"
       >
      <composite-id
          name="comp_id"
          class="com.iss.va.vo.impl.SecurityIndexPK"
      >
              <key-property
            name="securityId"
            type="java.lang.String"
            column="SecurityID"
            length="14"
         />
              <key-property
            name="securityTypeid"
            type="java.lang.Byte"
            column="SecurityTypeid"
            length="4"
         />
              <key-property
            name="indexTypeId"
            type="java.lang.Short"
            column="IndexTypeID"
            length="6"
         />
      </composite-id>
      <property
          name="companyName"
          type="java.lang.String"
          update="true"
          insert="true"
          access="property"
          column="CompanyName"
          length="60"
      />
      <property
          name="ticker"
          type="java.lang.String"
          update="true"
          insert="true"
          access="property"
          column="Ticker"
          length="20"
      />
      <property
          name="startDate"
          type="java.util.Date"
          update="true"
          insert="true"
          access="property"
          column="StartDate"
          length="19"
      />
      <property
          name="endDate"
          type="java.util.Date"
          update="true"
          insert="true"
          access="property"
          column="EndDate"
          length="19"
      />
      <many-to-one
          name="securitytypecode"
          class="com.iss.va.vo.impl.SecurityTypeCode"
          cascade="none"
          outer-join="false"
          update="false"
          insert="false"
          access="property"
      >
          <column
         name="SecurityTypeid"
          />
      </many-to-one>
      <many-to-one
          name="security"
          class="com.iss.va.vo.impl.Security"
          cascade="none"
          outer-join="false"
          update="false"
          insert="false"
          access="property"
      >
          <column
         name="SecurityTypeid"
          />
          <column
         name="SecurityID"
          />
      </many-to-one>
      <many-to-one
          name="company"
          class="com.iss.va.vo.impl.Company"
          cascade="none"
          outer-join="false"
          update="true"
          insert="true"
          access="property"
      >
          <column
         name="CompanyID"
          />
      </many-to-one>
       </class>
   </hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
   Session s = DAO.createSession();
   SecurityIndexPK pk2 = new SecurityIndexPK();
   pk2.setSecurityId("001204106");
   pk2.setSecurityTypeid( new Byte((byte)1));
   pk2.setIndexTypeId(new Short((short)6));
   Class c = com.iss.va.vo.impl.SecurityIndex.class;
   SecurityIndex securityIndex = (com.iss.va.vo.SecurityIndex) s.load(c, (com.iss.va.vo.impl.SecurityIndexPK)pk2);
   System.out.println("securityIndex=\n"+securityIndex);

Full stack trace of any exception that occurs:
Code:
   [WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: S1009
   [ERROR] JDBCExceptionReporter - Value '001204106' is out of range [-127,127]
   [WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: S1009
   [ERROR] JDBCExceptionReporter - Value '001204106' is out of range [-127,127]
   [ERROR] JDBCExceptionReporter - could not load: [com.iss.va.vo.impl.SecurityIndex#com.iss.va.vo.impl.SecurityIndexPK@63642865[securityId=001204106,securityTypeid=1,indexTypeId=6]] <java.sql.SQLException: Value '001204106' is out of range [-127,127]>java.sql.SQLException: Value '001204106' is out of range [-127,127]
      at com.mysql.jdbc.ResultSet.getByte(ResultSet.java:701)
      at com.mysql.jdbc.ResultSet.getByte(ResultSet.java:720)
      at net.sf.hibernate.type.ByteType.get(ByteType.java:18)
      at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
      at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
      at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
      at net.sf.hibernate.type.ComponentType.hydrate(ComponentType.java:387)
      at net.sf.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:145)
      at net.sf.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:61)
      at net.sf.hibernate.loader.Loader.hydrate(Loader.java:686)
      at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:627)
      at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:586)
      at net.sf.hibernate.loader.Loader.getRow(Loader.java:501)
      at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:213)
      at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
      at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
      at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:911)
      at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:931)
      at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
      at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
      at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
      at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2117)
      at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1991)
      at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1920)
      at Foo.fooB(Foo.java:50)
      at Foo.main(Foo.java:41)


Name and version of the database you are using:
mysqld-nt.exe Ver 4.0.20a-nt-log for NT on i32
mysql-connector-java-3.1.14

The generated SQL (show_sql=true):
Code:
   select securityin0_.SecurityID as SecurityID0_, securityin0_.SecurityTypeid as Security2_0_, securityin0_.IndexTypeID as IndexTyp3_0_, securityin0_.CompanyName as CompanyN4_0_, securityin0_.Ticker as Ticker0_, securityin0_.StartDate as StartDate0_, securityin0_.EndDate as EndDate0_, securityin0_.SecurityTypeid as Security2_0_, securityin0_.SecurityID as SecurityID0_, securityin0_.CompanyID as CompanyID0_ from securityindex securityin0_ where securityin0_.SecurityID=? and securityin0_.SecurityTypeid=? and securityin0_.IndexTypeID=?




Debug level Hibernate log excerpt:

debug

DB Info:

Code:
   mysql> describe securityindex;
   +----------------+-------------+------+-----+---------------------+-------+
   | Field          | Type        | Null | Key | Default             | Extra |
   +----------------+-------------+------+-----+---------------------+-------+
   | SecurityID     | varchar(14) |      | PRI |                     |       |
   | SecurityTypeid | tinyint(4)  |      | PRI | 0                   |       |
   | IndexTypeID    | smallint(6) |      | PRI | 0                   |       |
   | CompanyName    | varchar(60) |      |     |                     |       |
   | Ticker         | varchar(20) | YES  |     | NULL                |       |
   | StartDate      | datetime    |      |     | 0000-00-00 00:00:00 |       |
   | EndDate        | datetime    | YES  |     | NULL                |       |
   | CompanyID      | int(11)     | YES  | MUL | NULL                |       |
   +----------------+-------------+------+-----+---------------------+-------+
   8 rows in set (0.00 sec)
   
   

   --
   -- Table structure for table `securityindex`
   --
   CREATE TABLE securityindex (
     SecurityID varchar(14) NOT NULL default '',
     SecurityTypeid tinyint(4) NOT NULL default '0',
     IndexTypeID smallint(6) NOT NULL default '0',
     CompanyName varchar(60) NOT NULL default '',
     Ticker varchar(20) default NULL,
     StartDate datetime NOT NULL default '0000-00-00 00:00:00',
     EndDate datetime default NULL,
     CompanyID int(11) default NULL,
     PRIMARY KEY  (SecurityID,SecurityTypeid,IndexTypeID),
     KEY IDX_SecurityID2 (SecurityID),
     KEY IDX_SecurityTypeID2 (SecurityTypeid),
     KEY IDX_SecurityIndex_CompanyID_SecurityTypeID2 (CompanyID,SecurityTypeid),
     KEY hind_1794105432_8A2 (CompanyID),
     KEY hind_c_1794105432_3A2 (IndexTypeID),
     CONSTRAINT `SecurityIndex2Company2` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`CompanyID`),
     CONSTRAINT `SecurityIndex2Security2` FOREIGN KEY (`SecurityTypeid`, `SecurityID`) REFERENCES `secu
   rity` (`SecurityTypeID`, `SecurityID`),
     CONSTRAINT `SecurityIndex2SecurityTypeID2` FOREIGN KEY (`SecurityTypeid`) REFERENCES `securitytype
   code` (`SecurityTypeID`)
   ) TYPE=InnoDB;


A sample query:

mysql> select * from securityindex securityin0_ where securityin0_.SecurityID="001204106" and securityin0_.SecurityTypeid=1 and securityin0_.IndexType
ID=6;
+------------+----------------+-------------+--------------------+--------+---------------------+---------+-----------+
| SecurityID | SecurityTypeid | IndexTypeID | CompanyName | Ticker | StartDate | EndDate | CompanyID |
+------------+----------------+-------------+--------------------+--------+---------------------+---------+-----------+
| 001204106 | 1 | 6 | FOO Resources Inc. | FOO | 2004-02-25 10:31:00 | NULL | 316 |
+------------+----------------+-------------+--------------------+--------+---------------------+---------+-----------+
1 row in set (0.02 sec)

Java Class & PK:


import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* @hibernate.class
* table="securityindex"
*
*/
public class SecurityIndex extends ValueObjectImpl implements Serializable, com.iss.va.vo.SecurityIndex {

/** identifier field */
private com.iss.va.vo.impl.SecurityIndexPK comp_id;

/** persistent field */
private String companyName;

/** nullable persistent field */
private String ticker;

/** persistent field */
private Date startDate;

/** nullable persistent field */
private Date endDate;

/** nullable persistent field */
private com.iss.va.vo.impl.SecurityTypeCode securitytypecode;

/** nullable persistent field */
private com.iss.va.vo.impl.Security security;

/** persistent field */
private com.iss.va.vo.impl.Company company;

/** full constructor */
public SecurityIndex(com.iss.va.vo.impl.SecurityIndexPK comp_id, String companyName, String ticker, Date startDate, Date endDate, com.iss.va.vo.impl.SecurityTypeCode securitytypecode, com.iss.va.vo.impl.Security security, com.iss.va.vo.impl.Company company) {
this.comp_id = comp_id;
this.companyName = companyName;
this.ticker = ticker;
this.startDate = startDate;
this.endDate = endDate;
this.securitytypecode = securitytypecode;
this.security = security;
this.company = company;
}

/** default constructor */
public SecurityIndex() {
}

/** minimal constructor */
public SecurityIndex(com.iss.va.vo.impl.SecurityIndexPK comp_id, String companyName, Date startDate, com.iss.va.vo.impl.Company company) {
this.comp_id = comp_id;
this.companyName = companyName;
this.startDate = startDate;
this.company = company;
}

/**
* @hibernate.id
* generator-class="assigned"
*
*/
public com.iss.va.vo.impl.SecurityIndexPK getComp_id() {
return this.comp_id;
}

public void setComp_id(com.iss.va.vo.impl.SecurityIndexPK comp_id) {
this.comp_id = comp_id;
}
public com.iss.va.vo.SecurityIndexPK getPK() {
return (com.iss.va.vo.SecurityIndexPK)getComp_id();
}
public void setPK(com.iss.va.vo.SecurityIndexPK pk) {
setComp_id((com.iss.va.vo.impl.SecurityIndexPK)pk);
}

/**
* @hibernate.property
* column="CompanyName"
* length="60"
* not-null="true"
*
*/
public String getCompanyName() {
return this.companyName;
}

public void setCompanyName(String companyName) {
this.companyName = companyName;
}

/**
* @hibernate.property
* column="Ticker"
* length="20"
*
*/
public String getTicker() {
return this.ticker;
}

public void setTicker(String ticker) {
this.ticker = ticker;
}

/**
* @hibernate.property
* column="StartDate"
* length="19"
* not-null="true"
*
*/
public Date getStartDate() {
return this.startDate;
}

public void setStartDate(Date startDate) {
this.startDate = startDate;
}

/**
* @hibernate.property
* column="EndDate"
* length="19"
*
*/
public Date getEndDate() {
return this.endDate;
}

public void setEndDate(Date endDate) {
this.endDate = endDate;
}

/**
* @hibernate.many-to-one
* update="false"
* insert="false"
* outer-join="false"
*
* @hibernate.column
* name="SecurityTypeid"
*
*/
public com.iss.va.vo.impl.SecurityTypeCode getSecuritytypecode() {
return this.securitytypecode;
}

public void setSecuritytypecode(com.iss.va.vo.impl.SecurityTypeCode securitytypecode) {
this.securitytypecode = securitytypecode;
}

/**
* @hibernate.many-to-one
* update="false"
* insert="false"
* outer-join="false"
*
* @hibernate.column
* name="SecurityTypeid"
*
* @hibernate.column
* name="SecurityID"
*
*/
public com.iss.va.vo.impl.Security getSecurity() {
return this.security;
}

public void setSecurity(com.iss.va.vo.impl.Security security) {
this.security = security;
}

/**
* @hibernate.many-to-one
* not-null="true"
* outer-join="false"
* @hibernate.column name="CompanyID"
*
*/
public com.iss.va.vo.impl.Company getCompany() {
return this.company;
}

public void setCompany(com.iss.va.vo.impl.Company company) {
this.company = company;
}

public boolean equals(Object other) {
if ( !(other instanceof SecurityIndex) ) return false;
SecurityIndex castOther = (SecurityIndex) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}

}

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/** @author Hibernate CodeGenerator */
public class SecurityIndexPK implements Serializable, com.iss.va.vo.SecurityIndexPK {

/** identifier field */
private String securityId;

/** identifier field */
private Byte securityTypeid;

/** identifier field */
private Short indexTypeId;

/** full constructor */
public SecurityIndexPK(String securityId, Byte securityTypeid, Short indexTypeId) {
this.securityId = securityId;
this.securityTypeid = securityTypeid;
this.indexTypeId = indexTypeId;
}

/** default constructor */
public SecurityIndexPK() {
}

/**
* @hibernate.property
* column="SecurityID"
* length="14"
*
*/
public String getSecurityId() {
return this.securityId;
}

public void setSecurityId(String securityId) {
this.securityId = securityId;
}

/**
* @hibernate.property
* column="SecurityTypeid"
* length="4"
*
*/
public Byte getSecurityTypeid() {
return this.securityTypeid;
}

public void setSecurityTypeid(Byte securityTypeid) {
this.securityTypeid = securityTypeid;
}

/**
* @hibernate.property
* column="IndexTypeID"
* length="6"
*
*/
public Short getIndexTypeId() {
return this.indexTypeId;
}

public void setIndexTypeId(Short indexTypeId) {
this.indexTypeId = indexTypeId;
}

public String toString() {
return new ToStringBuilder(this)
.append("securityId", getSecurityId())
.append("securityTypeid", getSecurityTypeid())
.append("indexTypeId", getIndexTypeId())
.toString();
}

public boolean equals(Object other) {
if ( !(other instanceof SecurityIndexPK) ) return false;
SecurityIndexPK castOther = (SecurityIndexPK) other;
return new EqualsBuilder()
.append(this.getSecurityId(), castOther.getSecurityId())
.append(this.getSecurityTypeid(), castOther.getSecurityTypeid())
.append(this.getIndexTypeId(), castOther.getIndexTypeId())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getSecurityId())
.append(getSecurityTypeid())
.append(getIndexTypeId())
.toHashCode();
}

}
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 6:30 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Don't cross post !

The original post in at http://forum.hibernate.org/viewtopic.php?t=934451 and is currently answered.


Top
 Profile  
 
 Post subject: Apologies
PostPosted: Tue Sep 14, 2004 10:05 pm 
Newbie

Joined: Tue Sep 14, 2004 12:05 am
Posts: 5
Hi Bertrand,

Apologies for it. I posted to Tools by mistake. If you are an admin, please feel free to delete from there as it was a mistake.

Mike


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.