aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate for Teradata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate for Teradata" Watch "Hibernate for Teradata" New topic
Author

Hibernate for Teradata

Nageswar Kakolla
Ranch Hand

Joined: Jan 16, 2006
Posts: 71
Hi there,

Hibernate does not support Teradata database and I did manually written, config,mapping file and POJO file and when I try to test, I am getting following error

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating HibernateSessionFactory %%%%
org.hibernate.MappingException: Could not determine type for: java.lang.string, for columns: [org.hibernate.mapping.Column(METRO_NAME)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
at InitSessionFactory.initSessionFactory(InitSessionFactory.java:106)
at InitSessionFactory.getInstance(InitSessionFactory.java:54)
at TestClient.main(TestClient.java:31)
Exception in thread "main" org.hibernate.HibernateException: Could not initialize the Hibernate configuration
at InitSessionFactory.initSessionFactory(InitSessionFactory.java:111)
at InitSessionFactory.getInstance(InitSessionFactory.java:54)
at TestClient.main(TestClient.java:31)
Picked up _JAVA_OPTIONS: -Dawt.toolkit=mercury.awt.awtSW -Xrunmicsupp -Xbootclasspath/a:C:\PROGRA~1\COMMON~1\MERCUR~1\SHARED~1\JAVAAD~1\classes;C:\PROGRA~1\COMMON~1\MERCUR~1\SHARED~1\JAVAAD~1\classes\mic.jar


here is my code

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">teradata.jdbc.driver.TeradataDriver</property>
<property name="hibernate.connection.password">monday</property>
<property name="hibernate.connection.url">uri = jdbc:teradata://slgo1093/</property>
<property name="hibernate.connection.username">donb999</property>
<property name="hibernate.default_schema">LST</property>
<property name="hibernate.dialect">org.hibernate.dialect.GenericDialect</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<!-- <property name="current_session_context_class">thread</property> -->
<property name ="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory </property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<!-- Disable the second-level cache -->
<!-- <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> -->
<property name="cache.provider_class">org.hibernate.cache.OSCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="NqsMtro.hbm.xml" />
</session-factory>
</hibernate-configuration>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 2, 2006 9:47:52 AM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="NqsMtro" table="LISDVP30.NQS_MTRO">
<meta attribute="implement-equals">true</meta>
<cache usage="read-only"/>
<id name="metroName" type="string">
<column name="METRO_NAME" precision="9" scale="0" />
<generator class="assigned" />
</id>
<property name="metroName" type="java.lang.string">
<column name="METRO_NAME" precision="9" scale="0" />
</property>

<property name="regName" type="java.lang.string">
<column name="REG_NAME" precision="9" scale="0" />
</property>

</class>
</hibernate-mapping>

Test client



import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.transaction.JTATransaction;
import org.hibernate.context.*;

import sun.rmi.runtime.NewThreadAction;

import java.util.Iterator;

//import com.vladium.utils.timing.ITimer;
//import com.vladium.utils.timing.TimerFactory;


public class TestClient {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// Create an ITimer using the Factory class:
// final ITimer timer = TimerFactory.newTimer ();

Session newSession = InitSessionFactory.getInstance().getCurrentSession();

NqsMtro obj = new NqsMtro();
//obj.setMetroName("xcov178");
//
//obj.setRegName("Nag");


try{
//UserTransaction newTransaction = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
Transaction newTransaction = newSession.beginTransaction();
//timer.start();
//newSession.save(obj);

//List messages = newSession.load(LstAct.class, new Long(1));
Query query = newSession.createQuery("from NqsMtro");
java.util.List result = query.list();
//java.util.List messages2 = newSession.createSQLQuery("SELECT * from LST_ACT");
//System.out.println("Messages"+messages.size());

Iterator iter = result.iterator();

while(iter!=null && iter.hasNext()){
NqsMtro message = (NqsMtro)iter.next();
System.out.println("LSTACT Table and column :"+message.getMetroName());
System.out.println("LSTACT Table and column :"+message.getRegName());

}

newSession.getTransaction().commit();
//timer.stop();
//System.out.println("Time Duration "+timer.getDuration()+"ms");
newSession.close();
}
catch(RuntimeException ex){
newSession.getTransaction().rollback();
ex.printStackTrace();
}
}



}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


java.lang.string


Hmm. Is there such a class?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nageswar Kakolla
Ranch Hand

Joined: Jan 16, 2006
Posts: 71
Thanx paul for that my stupid mistake. I meant java.lang.String. I didnt know that will cost me.

Now i got following, My Question is what should I give class name for teradata driver. I just made up this "teradata.jdbc.driver.TeradataDriver
"


og4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating HibernateSessionFactory %%%%
org.hibernate.HibernateException: JDBC Driver class not found: teradata.jdbc.driver.TeradataDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at InitSessionFactory.initSessionFactory(InitSessionFactory.java:106)
at InitSessionFactory.getInstance(InitSessionFactory.java:54)
at TestClient.main(TestClient.java:31)
Caused by: java.lang.ClassNotFoundException: teradata.jdbc.driver.TeradataDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 9 more
Exception in thread "main" org.hibernate.HibernateException: Could not initialize the Hibernate configuration
at InitSessionFactory.initSessionFactory(InitSessionFactory.java:111)
at InitSessionFactory.getInstance(InitSessionFactory.java:54)
at TestClient.main(TestClient.java:31)
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
I believe it's com.ncr.teradata.TeraDriver

The Teradata JDBC Driver manual has some examples.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate for Teradata