Home Answers Viewqa Hibernate hibernate annotations

 
 


suresh anugandula
hibernate annotations
0 Answer(s)      a year and 11 months ago
Posted in : Hibernate

I am facing following problem, I have created 2 tables (student and address) with foreign key in address table. I am using hibernate annotations to insert records into these tables. But it is trying to insert records into 'student_tbl_address_tbl' which is not created in database.

Following ar pojo classes

  - Student.java

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="student_tbl")

public class Student implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 8876327743522818732L;


    @Id
    private long sid;
    @Column(name="sname")
    private String sname;
    @Column(name="age")
    private double age;
    @OneToMany(cascade=CascadeType.ALL)
    private Set<Address> addresses=new HashSet<Address>(0);


    @OneToMany(mappedBy="student",cascade=CascadeType.ALL)
    public Set<Address> getAddresses() {
        return addresses;
    }
    public void setAddresses(Set<Address> addresses) {
        this.addresses = addresses;
    }
    public long getSid() {
        return sid;
    }
    public void setSid(long sid) {
        this.sid = sid;
    }
    public String getSname() {
        return sname;
    }
    public void setSname(String sname) {
        this.sname = sname;
    }

    public double getAge() {
        return age;
    }
    public void setAge(double age) {
        this.age = age;
    }
}

  - Address.java

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="address_tbl")
public class Address implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 6583374367093492573L;
    @Id
    long adno;
    @Column(name="street")
    String street;
    @Column(name="city")
    String city;
    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="sid")
    Student student;
    public long getadno() {
        return adno;
    }
    public void setadno(long adno) {
        this.adno = adno;
    }
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public Student getStudent() {
        return student;
    }
    public void setStudent(Student student) {
        this.student = student;
    }


}

I have created following class to store the records inside the database

  - Write.java

import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class Write {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Session session=HibernateSessionFactory.getSession();
        Transaction tx=session.beginTransaction();

        Student s=new Student();
        s.setAge(25d);
        s.setSid(1l);
        s.setSname("suresh");

        Set<Address> addressSet=new HashSet<Address>();
        Address a=new Address();
        a.setadno(1l);
        a.setCity("hyd");
        a.setStreet("kukatpally");
        a.setStudent(s);
        addressSet.add(a);

        a=new Address();
        a.setadno(2l);
        a.setCity("sec");
        a.setStreet("ameerpet");
        a.setStudent(s);

        addressSet.add(a);
        s.setAddresses(addressSet);
        session.save(s);

        tx.commit();

        session.close();

    }

}

following is the exception i got,

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select address_.adno, address_.city as city1_, address_.street as street1_, address_.sid as sid1_ from address_tbl address_ where address_.adno=?
Hibernate: select address_.adno, address_.city as city1_, address_.street as street1_, address_.sid as sid1_ from address_tbl address_ where address_.adno=?
Hibernate: insert into student_tbl (age, sname, sid) values (?, ?, ?)
Hibernate: insert into address_tbl (city, street, sid, adno) values (?, ?, ?, ?)
Hibernate: insert into address_tbl (city, street, sid, adno) values (?, ?, ?, ?)
Hibernate: insert into student_tbl_address_tbl (student_tbl_sid, addresses_adno) values (?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert collection: [com.tbss.Student.addresses#1]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1205)
    at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
    at com.tbss.Write.main(Write.java:41)
Caused by: java.sql.SQLException: Invalid object name 'student_tbl_address_tbl'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
    at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
    at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
    at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:504)
    at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
    at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1168)
    ... 10 more

Please send the answer to "Anugandula.Suresh@Tata-bss.com"
View Answers









Related Pages:
Hibernate Annotations ManytoMany - Hibernate
Hibernate Annotations ManytoMany  Can anybody tell me how to have a many to many relationship through Hibernate Annotations not through the Hbm.xml files plz
hibernate annotations
hibernate annotations to insert records into these tables. But it is trying...hibernate annotations  I am facing following problem, I have created... system properly. Hibernate: select address_.adno, address_.city as city1
Hibernate Annotations
This tutorial describes the concept of annotations
hibernate annotations example for mappings
hibernate annotations example for mappings  Please send me example of hibernate annotations for mappings.Please send the example   Please go through the following link: Hibernate Annotations
Hibernate 4 annotations tutorial
Hibernate 4 annotations tutorial  Hi, I am trying to find the best Hibernate 4 annotations tutorial. I think there is good tutorial on your site. Please tell me the url of Hibernate 4 annotations tutorial. Thanks   hi
Hibernate Annotations
Hibernate Annotations In this section we will learn about Hibernate Annotations and understand how Hibernate Annotations is simplifying the programming... as Hibernate annotations and it based on the Java 5 annotations. So, to use Hibernate
Spring Hibernate Annotations
In this section, you will learn about the common annotations used for Spring Hibernate Integration
Hibernate mapping annotations
In this section, you will learn about the annotations used for various mapping in Hibernate
Hibernate 4 Annotations
Hibernate 4 Annotations In this tutorial you will learn about the use of annotations in Hibernate. To create an example in Hibernate using Annotation reader... and do process as it is defined for. Hibernate also needs to provide
Hibernate Annotations
Hibernate Annotations       You have... Annotations part.  Download Source Code Hibernate Annotations: Hibernate needs... and does the processing accordingly. The Hibernate Annotations is the powerful
Unable to create annotations in hibernate 4.0
Unable to create annotations in hibernate 4.0  I worked on a similar example as yours.But when I create a new hibernate console configuration... is deprecated in hibernate 4.0 ,hence I used Configuration object as shown by you. Kindly
Hibernate Annotations
Hibernate Annotations       Hibernate Annotations examples and tutorials. Quick Hibernate... accordingly. The Hibernate Annotations is the powerful way to provide the metadata
hibernate annotations with composite primary key
hibernate annotations with composite primary key  I want to know how to use hibernate annotations in case of composite primary key in one table. I... the following link: Hibernate Notations
Hibernate Validator Annotations
In this section, you will learn how to validate in Hibernate using validator annotations in bean class
Hibernate Annotations Example
Hibernate Annotations Example In this section we will see how we can develop Hibernate Annotations based example program. After completing this tutorial you will be able to use Hibernate Annotations in your project and develop
Hibernate One to Many Self Join using Annotations
In this section, you will learn one to many self join using Annotations in Hibernate
Hibernate Many to Many Self Join using Annotations
In this section, you will learn how to do many to many self join using Annotations in Hibernate
hibernate
why hibernate?  why hibernate?   Hibernate: -Hibernate... library. It solves object-relational impedance mismatch problems. Hibernate makes the application development process easy Hibernate saves the development
Annotations
Annotations       Sun... efficient in jdk 5. The main objective to develop the annotations is to make the development easier. Annotations behaves like the meta. The literal meaning
Annotations
Annotations       Annotations in computer programming languages provide data about a program... directly to the operation of the code to which they annotate. Annotations
Hibernate Annotattions - Hibernate
hibernate annotations which is a new facility in hibernate 3.2 any tutorial and what.... The Hibernate Annotations is the powerful way to provide the metadata for the Object.../hibernateannotations/hibernate-annotations-tutorial.shtml http
Annotations
Annotations       Sun... efficient in jdk 5. The main objective to develop the annotations is to make the development easier. Annotations behaves like the meta. The literal meaning
Hibernate Configuration
The configuration of Hibernate is handled by the instance of org.hibernate.cfg.Configuration . It symbolizes the complete mapping between Java data types... org.hibernate.SessionFactory . Various XML mapping files or Java Annotations compilation build
Hibernate Mapping
the O/R mappings. Annotations are also well supported in hibernate. You can... also talks about hibernate annotations mapping. In this tutorial we will use xml file defining object/relational mapping, but in the Hibernate annotations
java - Hibernate
the code and run using Hibernate and annotation..plse help me...  Hi friend, Read for more information. http://www.roseindia.net/hibernate/hibernateannotations/hibernate-annotations-tutorial.shtml Thanks
Annotations are using now a days?
Annotations are using now a days?  i have a doubt in Annatation, if we use Annatation we must hardcoding the code/data but sunmicrosystem itself says that hardcoding is not recommended
Hibernate 4
; Element Hibernate 4 Annotations Hibernate 4 Annotation Example...Hibernate 4 Hibernate 4 is the latest version of Hibernate which was released in Jan, 2012. Hibernate 4 comes with many new features such as Multi-tenancy
spring mvc3 and hibernate with annotation example
spring mvc3 and hibernate with annotation example  please send an example which is used to store the form data into database using spring with hibernate using annotations
Annotations in Java
Annotations behave like metadata and provide data about a program... the annotated elements. Developing Annotations helps in faster development of program. Use of Annotations: Compiler can use Annotations to detect errors
Hibernate 3 Query Example Part 2
Hibernate 3 Query Example Part 2       Hibernate 3 Query Example Part 2 This tutorial  explains  how to create  Hibernate 3 query example with Spring 3 
Why hibernate is used?
Why hibernate is used? Hibernate is leading ORM solutions for developing... and the application developing is also very simple if Hibernate is used in the application. Hibernate makes the application development process easy
Spring 3 MVC and Hibernate 3 Example Part 1
Spring 3 MVC and Hibernate 3 Example application using Annotations This tutorial explains how to use annotations with spring 3 MVC and hibernate 3 based application to make the development easier and faster than ever before. You can
Complete Hibernate 4.0 Tutorial
Hibernate 4 Annotations Hibernate 4 Annotation Example Hibernate update... using Annotations Hibernate Many to Many Self Join using Annotations Hibernate Bi-directional Mapping Hibernate One
Hibernate with Annotation
is used to write the metadata information in Hibernate.   Annotations... the runtime by JVM and does the processing accordingly. The Hibernate Annotations...Hibernate with Annotation      
Hibernate Tools
from hibernate mappings/ EJB annotations Learn how to use HQL/EJBQL query... Hibernate Tools Hibernate Tools: Hibernate Tool is yet another cool set of tools from Hibernate.org to help the developers in hibernate programming
Hibernate Training
Hibernate Training        Hibernate Training Course Objectives Learning Fundamentals of  Hibernate by using the Hibernate persistence
Sitemap Hibernate Tutorial
| Hibernate Mapping | Hibernate Annotations | Build and testing...; Tutorial Section Introduction to Hibernate 3.0 | Hibernate Architecture | First Hibernate Application | Running the Example in Eclipse | Understanding
Hibernate criteria conjunction..
Hibernate criteria conjunction..  What is criteria conjunction in Hibernate?    In Hibernate, Criteria Conjunction works as logical... of bellow example- Steps- 1.Copy library (jar file) of hibernate into your lib folder
Spring 3 MVC and Hibernate 3 Example Part 2
. <bean id="dataSource"> provides properties to hibernate to make it able to create session factory. Hibernate uses instance of session bean...;annotatedClasses"> element provides hibernate the list of annotated classes. 
Spring 3 MVC and Hibernate 3 Example Part 3
and Hibernate 3 Example application using Annotations</title> </head> <body> <h1>Spring 3 MVC and Hibernate 3
HIBERNATE
HIBERNATE   What is difference between Jdbc and Hibernate
hibernate
hibernate  what is hibernate listeners
hibernate
hibernate  what is hibernate flow
Hibernate Search
text searching. Hibernate search also uses Annotations and EntityManager. Lucene... Hibernate Search       In this section we will learn about Hibernate Search, which is used create
JDBC4.0-Dataset implementation of SQL using Annotations
JDBC4.0-Dataset implementation of SQL using Annotations An annotation..., are used to inject code at runtime.The Annotations allows developers.... There are two main annotations when specifying SQL queries in Java code
CRUD application in hibernate annotation
CRUD application in hibernate annotation      ... using hibernate annotation.  Table name: student CREATE TABLE... in hibernate annotation. Step 1:- Creating Utility Class :- The following
hibernate
hibernate  how to uses optional column in hibernate
hibernate
hibernate  please give me the link where i can freely download hibernate software(with dependencies)   Learn hibernate, if you want to learn hibernate, please visit the following link: Hibernate Tutorials
Hibernate
Hibernate  hibernate delete query execution

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.