-->
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: Why not store feedback database ?
PostPosted: Mon May 19, 2008 12:12 am 
Newbie

Joined: Sun May 18, 2008 11:57 pm
Posts: 4
Hi !
I'm using Oracle 10, Hibernate3.0 and IDE NetBeans.
When I run my applycation, I'm insert into Database Table some records. And I turn on SQL Navigator to show my data in my datatable(when my app runtime), I saw them(my records above). But, when I closed NetBeans IDE and Show my data again(In SQL Navigator) then my data was loose !!! Why ? Please training for me this problem.
This is my code :

hibernate.cfg.xml
===================================
<?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>

<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@10.4.0.10:1521:PTUD</property>
<property name="connection.username">SCOTT</property>
<property name="connection.password">tiger</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</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="hibernate_lesson_01/Event.hbm.xml"/>

</session-factory>

</hibernate-configuration>

Persitan Class Task.java :
==================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package firsthibernate.persitans;

import java.io.Serializable;

public class Task implements Serializable{
private int id = 0;
private String taskname = "";
private boolean status = false;

public Task(){

}
public Task(int id,String name,boolean state) {
this.id = id;
taskname = name;
status = state;
}
public Task(String name,boolean state){
taskname = name;
status = state;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getTaskname(){
return taskname;
}
public void setTaskname(String name){
taskname = name;
}
public boolean getStatus(){
return status;

}
public void setStatus(boolean state){
status = state;
}
}

Maping file Task.hbm.xml:
===================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="firsthibernate.persitans.Task" table="TASKS">
<id name="id" column="id">
<generator class="increment"/>
</id>
<property name="taskname"/>
<property name="status"/>
</class>
</hibernate-mapping>

HibernateUtil.java:
====================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package util;
import net.sf.cglib.proxy.*;
import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}


}

Main.java :
=======================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package firsthibernate;

import org.hibernate.Session;
import util.HibernateUtil;
import firsthibernate.persitans.Task;
import java.util.List;

/**
*
* @author Nguyen Tien Dung
*/
public class Main
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

for (int i = 1; i < 10; i++)
{
Task theTask = new Task("Task_" + i, true);

session.save(theTask);
}
session.getTransaction().commit();

List lst = listEvents();
for(int i=0;i<lst.size();i++)
{
Task tsk = (Task)lst.get(i);
System.out.printf("%s\t%b\n",tsk.getTaskname(),tsk.getStatus());
}

}

private static List listEvents()
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

List result = session.createQuery("from Task").list();

session.getTransaction().commit();

return result;
}
}

Folder :
+ src
hibernate.cfg.xml
+ firsthibernate
Main.java
+ firsthibernate.persitans
Task.java
Task.hbm.xml
+ util
HibernateUtil.java


Last edited by hungvuonghdu on Sun May 25, 2008 10:46 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 4:27 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'm seeing several problems:
Quote:
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

This driver is for Microsoft SQL Server or Sybase; you said you are using Oracle so you should use a Oracle driver.

Quote:
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>

Also the dialect should match your Database type.

regards,

_________________
Sanne
http://in.relation.to/


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.