Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
hi,
iam new to hibernate .
i am creating an new hibernate example
/**
*
*/
package hibernate.oracle.model;
import java.io.Serializable;
import java.sql.SQLException;
import javax.persistence.Entity;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.SequenceGenerator;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;
import com.ddtek.jdbc.extensions.ExtEmbeddedConnection;
/**
* @author Administrator
*
*/
@Entity
public class Users implements Serializable{
private Long id;
private String password;
/**
* @return the id
*/
@Id
@SequenceGenerator(allocationSize=7,initialValue=10,name="cmn_user_seq",sequenceName="USER_SEQ" )
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="cmn_user_seq" )
//@GeneratedValue
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
*
*/
public Users() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
try{
AnnotationConfiguration lAnnotationConfigure = new AnnotationConfiguration();
lAnnotationConfigure.addAnnotatedClass(Users.class);
lAnnotationConfigure.configure();
SessionFactory lSessionFactory = lAnnotationConfigure.buildSessionFactory();
System.out.println(lAnnotationConfigure instanceof ExtEmbeddedConnection);
Session lSession = lSessionFactory.getCurrentSession();
lSession.beginTransaction();
Users lUser = new Users();
lUser.setPassword("password");
Users lUser1 = new Users();
lUser1.setPassword("synaptris");
Long id = (Long)lSession.save(lUser);
Long id1 = (Long)lSession.save(lUser1);
System.out.println("THE ID IS "+id);
System.out.println("THE ID OF USER IS "+id1);
lSession.getTransaction().commit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
but everytime i run this program
i see i the log information like this
23:26:21,531 INFO SchemaExport:226 - Running hbm2ddl schema export
23:26:21,531 DEBUG SchemaExport:242 - import file not found: /import.sql
23:26:21,531 INFO SchemaExport:251 - exporting generated schema to database
23:26:21,531 DEBUG SchemaExport:377 - drop table Users cascade constraints
23:26:21,640 DEBUG SchemaExport:377 - drop sequence USER_SEQ
23:26:21,656 DEBUG SchemaExport:377 - create table Users (id number(19,0) not null, password varchar2(255 char), primary key (id))
23:26:21,718 DEBUG SchemaExport:377 - create sequence USER_SEQ
23:26:21,718 INFO SchemaExport:268 - schema export complete
i think i drops the table everytime and creates a new one.
The problem is it never creates a new record if i run again the same program.
can anyone help me to solve this.
thank you