aspose file tools*
The moose likes Java in General and the fly likes Hibernate project Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hibernate project Exception" Watch "Hibernate project Exception" New topic
Author

Hibernate project Exception

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Hi,



I am running a example project from intertnet and got exception like



log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select hibernate_sequence.nextval from dual
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy5.save(Unknown Source)
at roseindia.CreateData.main(CreateData.java:21)
Caused by: java.sql.SQLException: ORA-02289: sequence does not exist

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:330)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:287)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:742)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:812)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1048)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:853)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1153)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3369)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3414)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:75)
... 16 more


createData java looks like

package roseindia;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class CreateData {


public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub

SessionFactory sessFact = HibernateUtil.getSessionFactory();
Session sess = sessFact.getCurrentSession();
org.hibernate.Transaction tr = sess.beginTransaction();

Student stu = new Student();
stu.setSname("Ganesh");
stu.setSroll(100);
stu.setScourse("B.C.A.");

sess.save(stu);//Save data
tr.commit();
System.out.println("Successfully inserted");
//sess.close();
}

}



student.java looks like


/**
*
*/
package roseindia;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import javax.persistence.Table;;

/**
* @author Rose India
*
*/
@Entity
@Table(name = "student")

public class Student implements Serializable{


@Id
@GeneratedValue

private int id;
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Column(name="sname", nullable=false,length=40)
private String sname;
public String getSname() {
return sname;
}

public void setSname(String sname) {
this.sname = sname;
}

@Column(name="sroll",nullable=false)
private int sroll;
public int getSroll() {
return sroll;
}

public void setSroll(int sroll) {
this.sroll = sroll;
}

@Column(name="scourse",nullable=false,length=10)
private String scourse;
public String getScourse() {
return scourse;
}

public void setScourse(String scourse) {
this.scourse = scourse;
}

}



hibernate.cfg.xml looks like

<?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.driver.OracleDriver</property>
<property name="connection.url">jdbcracle:thin:@localhost:1521rcl</property>
<property name="connection.username">deliverytest7</property>
<property name="connection.password">dbpassword</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</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">none</property>

<mapping class="roseindia.Student"/>

</session-factory>
</hibernate-configuration>



hibernate util class looks like


package roseindia;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
//Singleton class
private static final SessionFactory sessionFactory;
static{
try{
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
}catch(Throwable th){
System.err.println("Enitial SessionFactory creation failed"+th);
throw new ExceptionInInitializerError(th);
}
}

public static SessionFactory getSessionFactory(){
return sessionFactory;
}

}


I was able to insert values outside hibernate through regular java program without any issues.

Any links, resources, ideas, sample code highly appreciated. Thanks in advance










Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Please take the time to choose the correct forum for your posts. This forum is for questions on advanced Java.

For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
i found the answer...how to close the question. please advise
Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
entity class i changed like

finally this one worked fine

public class Student implements Serializable{


@Id

@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="STUDENTID")
@SequenceGenerator(name="STUDENTID", sequenceName = "STUDENTID")
 
wood burning stoves
 
subject: Hibernate project Exception