-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems reverse engineering oracle timestamp
PostPosted: Tue Aug 05, 2008 10:45 am 
Newbie

Joined: Tue Aug 05, 2008 10:11 am
Posts: 1
Hibernate version: 3.2.4.sp1

Name and version of the database you are using:Oracle 10g 10.2.0.4.0. Drivers: ojdbc14.jar

Hello,

I'm having problems reverse engineering an existing oracle database using hibernate tools. The oracle datatype timestamp(6) gets generated as java.io.Serializable, not as timestamp.

The generated class (the columns ADDED_DATE and CHANGED_DATE are of type timestamp(6)):
Code:
package com.testproj.model;
// Generated 2008-aug-05 16:33:56 by Hibernate Tools 3.2.0.CR1

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

/**
* NfOrganisation generated by hbm2java
*/
@Entity
@Table(name = "NF_ORGANISATION")
public class NfOrganisation implements java.io.Serializable {

   private String organisationId;
   private String beskrivning;
   private Serializable addedDate;
   private Serializable changedDate;

   public NfOrganisation() {
   }

   public NfOrganisation(String organisationId) {
      this.organisationId = organisationId;
   }
   public NfOrganisation(String organisationId, String beskrivning,
         Serializable addedDate, Serializable changedDate) {
      this.organisationId = organisationId;
      this.beskrivning = beskrivning;
      this.addedDate = addedDate;
      this.changedDate = changedDate;
   }

   @Id
   @Column(name = "ORGANISATION_ID", unique = true, nullable = false, length = 100)
   @NotNull
   @Length(max = 100)
   public String getOrganisationId() {
      return this.organisationId;
   }

   public void setOrganisationId(String organisationId) {
      this.organisationId = organisationId;
   }

   @Column(name = "BESKRIVNING", length = 100)
   @Length(max = 100)
   public String getBeskrivning() {
      return this.beskrivning;
   }

   public void setBeskrivning(String beskrivning) {
      this.beskrivning = beskrivning;
   }

   @Column(name = "ADDED_DATE")
   public Serializable getAddedDate() {
      return this.addedDate;
   }

   public void setAddedDate(Serializable addedDate) {
      this.addedDate = addedDate;
   }

   @Column(name = "CHANGED_DATE")
   public Serializable getChangedDate() {
      return this.changedDate;
   }

   public void setChangedDate(Serializable changedDate) {
      this.changedDate = changedDate;
   }

}


When trying to deploy the generated app I get this exception:

Code:
16:30:39,284 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

--- MBeans waiting for other MBeans ---
ObjectName: persistence.units:ear=testproj.ear,unitName=testproj
  State: FAILED
  Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: ADDED_DATE, expected: raw(255)
  I Depend On:
    jboss.jca:service=DataSourceBinding,name=testprojDatasource


How can I solve this?

\\daniel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 2:03 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
I ran into this same problem. You have to set up the type-mappings to tell Hibernate how to map different types it may find. In my situation I used the "Reverse Engineer from the JDBC Connection" option. This option allowed me to provide a reveng.xml file where I defined my type-mappings. See the Hibernate Tools Reference Guide 5.2.2 for more details. If you are not using the "Reverse Engineer from the JDBC Connection" option, you will have to find another way to tell hibernate about you type-mappings.

Here is a snippet of my reveng.xml file:

Code:
<hibernate-reverse-engineering>
    <type-mapping>
        <sql-type jdbc-type="TIMESTAMP" hibernate-type="java.sql.Timestamp" />
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" />
        <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Long" />
        <sql-type jdbc-type="VARCHAR" length="1" not-null="true" hibernate-type="java.lang.Character" />
        <!--sql-type jdbc-type="VARCHAR" hibernate-type="your.package.TrimStringUserType" /-->
        <sql-type jdbc-type="VARCHAR" length="1" hibernate-type="char" />
        <sql-type jdbc-type="VARCHAR" hibernate-type="string" />
    </type-mapping>
    .
    .
    .
</hibernate-reverse-engineering>


Hope this helps!

_________________
pouncilt


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