How to match oracle timestamp for corresponding java type in sleep mode?

I am new to sleep mode and am at a standstill. My database has tables with TIMESTAMP(6) columns TIMESTAMP(6) . I am using Netbeans 6.5.1, and when I create hibernate.reveng.xml , hbm.xml files and pojo files , it sets up columns of type Serializable . This is not what I expected, and what I want them to be.

I found this post on sleep mode forums that says:

 <sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" /> 

in the hibernate.reveng.xml file.

In Netbeans, you cannot generate mappings from this file (each time it creates a new one), and it does not seem to have the ability to regenerate them from a file (at least according to this , it will be available in version 7).

So, I'm trying to figure out what to do. I am more likely to believe that I am doing something wrong, as I am new to this, and it seems like this will be a common problem for others.

  • So what am I doing wrong?
  • If I'm not mistaken, how can I do this?

I use Netbeans 6.5, Oracle 10G, and I believe that Hibernate 3 (it came with my netbeans).

Edit: Suppose I found https://stackoverflow.com/a/312947/

UPDATE: The oracle jdbc driver I used (ojdbc14.jar) is 9.0.2.0.0 I also tried:

  • ojdbc14.jar version 10.2.0.4.0
  • ojdbc6.jar version 11.2.0.1.0
+4
source share
2 answers

I found a job for this problem. The problem itself seems to be due to the fact that Netbeans 6.5 (and later versions up to this point) do not allow you to process the database from the existing hibernate.reveng.xml file. It will be available in version 7.

The work discovered is to create an ant task to recreate the hbm.xml and pojo java files. Currently, this happens for me when I am doing clean and assembly, but I will try to find a way to completely separate it, since this will only need to be run when the database schema changes.

To accomplish this when you do clean and build, but you need to edit the build.xml file.

The first part is the libraries you need. So add:

 <path id="toolslib"> <path location="lib/hibernate-support/hibernate-tools.jar" /> <path location="lib/hibernate-support/hibernate3.jar" /> <path location="lib/hibernate-support/freemarker.jar" /> <path location="lib/hibernate-support/jtidy-r938.jar" /> <path location="lib/ojdbc14.jar" /> </path> 

You should already have the hibernate-tools.jar, hibernate3.jar, and ojdbc14.jar files on your computer. So just change the path to them. freemaker.jar and jtidy-r938.jar will need to be downloaded, since I didn’t have them.

Below this in build.xml you need to add:

 <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib"> <classpath> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> </classpath> </taskdef> 

The last section you will need is the set to run in the section after cleaning:

 <target name="-post-clean"> <delete dir="src/*Put the foler where your pojos and hbm.xml files are located*"/> <hibernatetool> <jdbcconfiguration configurationfile="src\hibernate.cfg.xml" packagename="*the package where you want them recreated*" revengfile="src\hibernate.reveng.xml" detectmanytomany="true" /> <hbm2hbmxml destdir="src" /> <hbm2java destdir="src" /> </hibernatetool> </target> 
  • The deletion part will delete the existing hbm and pojo files before they are recreated.
  • configurationfile points to your main configuration file.
  • The package name is the point package you want to create ( com.stackoverflow.pojo for example).
  • revengfile is a reverse engineering XML file that should be used when creating hbm and pojo files.
  • hbm2hbmxml will create the hbm2hbmxml files of your tables.
  • hbm2java will create the java pojo files of your tables.

Now for the Oracle Timestamps to be something other than Serializable , edit the hibernate.reveng.xml file and add:

 <type-mapping> <sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" /> </type-mapping> 

immediately after the schema select tag.

Thus, pure and string and timestamps will not be java.sql.Timestamp instead of Serializable objects.

This is a long answer that I know, but it should also work for any other changes that you will need to install in the hibernate.reveng.xml file (I think). I am not an expert in sleep mode, so your mileage may change.

UPDATE: Therefore, after some searches, I found this site about user ant tasks in Netbeans. Therefore, I just changed the name of the target as gen-dao , and now it does not start every time I do a clean and build, only when I specifically call it.

+2
source

I ran into a similar problem and solved it by writing my own RevengNamingStrategy.

I have a table with two columns like TIMESTAMP_WITH_TIMEZONE and TIMESTAMP_WITH_LOCAL_TIMEZONE and during reverse engineering they are converted to seralizable.

SqlTypes of types TIMESTAMP_WITH_TIMEZONE and TIMESTAMP_WITH_LOCAL_TIMEZONE are -101 and -102.And Since there are no types of sleep mode types in java.sql.Types for these types, therefore, they are mapped to seralizable.

So I wrote my own RevengNamingStrategy, which converts these types to Timestamp. Which intern converts TimeStampType to sleep mode.

 public class OracleRevengNamingStrategy extends DefaultRevengNamingStrategy { private static final Integer TIMESTAMP_WITH_TIMEZONE_SQL_CODE = -101; private static final Integer TIMESTAMP_WITH_LOCAL_TIMEZONE_SQL_CODE = -102; public OracleRevengNamingStrategy(ReverseEngineeringStrategy delegate) { super(delegate); } // Converts Timestamp with tomezone and Time stamp with local time zone to Timestamp @Override public String columnToHibernateTypeName(TableIdentifier table, String columnName, int sqlType, int length, int precision, int scale, boolean nullable, boolean generatedIdentifier) { String type; if (sqlType == TIMESTAMP_WITH_TIMEZONE_SQL_CODE || sqlType == TIMESTAMP_WITH_LOCAL_TIMEZONE_SQL_CODE) { type = "timestamp"; } else { type = super.columnToHibernateTypeName(table, columnName, sqlType, length, precision, scale, nullable, generatedIdentifier); } return type; } } 
+1
source

Source: https://habr.com/ru/post/1304518/


All Articles