hibernate annotations

hibernate annotations

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 "[email protected]"
View Answers









Related Tutorials/Questions & Answers:
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
Version of hibernate>hibernate-annotations dependency
List of Version of hibernate>hibernate-annotations dependency
Advertisements
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 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
Maven Repository/Dependency: hibernate-annotations | hibernate-annotations
Maven Repository/Dependency of Group ID hibernate-annotations and Artifact ID hibernate-annotations. Latest version of hibernate-annotations:hibernate-annotations dependencies. # Version Release Date
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
Hibernate mapping annotations
In this section, you will learn about the annotations used for various mapping in Hibernate
Spring Hibernate Annotations
In this section, you will learn about the common annotations used for Spring Hibernate Integration
Maven Dependency hibernate-annotations >> 3.0beta1
You should include the dependency code given in this page to add Maven Dependency of hibernate >> hibernate-annotations version3.0beta1 in your project
Maven Dependency hibernate-annotations >> 3.0beta2
You should include the dependency code given in this page to add Maven Dependency of hibernate >> hibernate-annotations version3.0beta2 in your project
Maven Dependency hibernate-annotations >> 3.1beta4
You should include the dependency code given in this page to add Maven Dependency of hibernate >> hibernate-annotations version3.1beta4 in your project
Maven Dependency hibernate-annotations >> 3.0alpha3
You should include the dependency code given in this page to add Maven Dependency of hibernate >> hibernate-annotations version3.0alpha3 in your project
Maven Dependency hibernate-annotations >> 3.1beta3
You should include the dependency code given in this page to add Maven Dependency of hibernate >> hibernate-annotations version3.1beta3 in your project
Maven Repository/Dependency: hibernate | hibernate-annotations
Maven Repository/Dependency of Group ID hibernate and Artifact ID hibernate-annotations. Latest version of hibernate:hibernate-annotations dependencies. # Version Release Date 1
Maven Repository/Dependency: hibernate-commons-annotations | hibernate-commons-annotations
Maven Repository/Dependency of Group ID hibernate-commons-annotations and Artifact ID hibernate-commons-annotations. Latest version of hibernate-commons-annotations:hibernate-commons-annotations dependencies
Hibernate 5 Annotations Maven dependency
Hibernate 5 Annotations Maven dependency to add in pom.xml Hibernate 5 uses... to the project. The Hibernate 5 Annotations Maven dependency jar files is necessary to use the annotations in Hibernate 5 Java project. You can manually download
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 CodeADS_TO_REPLACE_1 Hibernate Annotations... the runtime by JVM and does the processing accordingly. The Hibernate Annotations
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 Validator Annotations
In this section, you will learn how to validate in Hibernate using validator annotations in bean class
Hibernate One to Many Self Join using Annotations
In this section, you will learn one to many self join using Annotations in Hibernate
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 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 Annotations
Hibernate Annotations       Hibernate Annotations examples and tutorials. Quick Hibernate... accordingly. The Hibernate Annotations is the powerful way to provide the metadata
Hibernate Annotations
This tutorial describes the concept of annotations
Maven Repository/Dependency: org.hibernate | hibernate-annotations
Maven Repository/Dependency of Group ID org.hibernate and Artifact ID hibernate-annotations. Latest version of org.hibernate:hibernate-annotations dependencies. # Version Release Date
Maven Repository/Dependency: org.netbeans.external | hibernate-annotations
Maven Repository/Dependency of Group ID org.netbeans.external and Artifact ID hibernate-annotations. Latest version of org.netbeans.external:hibernate-annotations dependencies. # Version Release Date
Maven Repository/Dependency: maven2.org.hibernate | hibernate-annotations
Maven Repository/Dependency of Group ID maven2.org.hibernate and Artifact ID hibernate-annotations. Latest version of maven2.org.hibernate:hibernate-annotations dependencies. # Version Release Date
Hibernate 4 Annotations Tutorial
Video Tutorial: Hibernate 4 Annotations Tutorial In this video tutorial I will explain you the steps needed to create example program using Annotations... such applications. We have used the Eclipse IDE. What is Hibernate Annotations?ADS
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
Maven dependency for hibernate - hibernate-annotations version 3.1beta3 is released. Learn to use hibernate-annotations version 3.1beta3 in Maven based Java projects
-annotations released The developers of   hibernate - hibernate..., the released version of  hibernate - hibernate-annotations library is 3.1beta3. Developer can use this version ( hibernate - hibernate-annotations version
Maven dependency for hibernate - hibernate-annotations version 3.1beta4 is released. Learn to use hibernate-annotations version 3.1beta4 in Maven based Java projects
-annotations released The developers of   hibernate - hibernate..., the released version of  hibernate - hibernate-annotations library is 3.1beta4. Developer can use this version ( hibernate - hibernate-annotations
Maven Repository/Dependency: org.hibernate | hibernate-commons-annotations
Maven Repository/Dependency of Group ID org.hibernate and Artifact ID hibernate-commons-annotations. Latest version of org.hibernate:hibernate-commons-annotations dependencies. # Version Release Date
org.hibernate.common - hibernate-commons-annotations version 5.0.2.Final Maven dependency. How to use hibernate-commons-annotations version 5.0.2.Final in pom.xml?
5.0.2.Final of hibernate-commons-annotations in pom.xml? How to use hibernate... 5.0.2.Final of hibernate-commons-annotations in project by the help of adding... ( org.hibernate.common - hibernate-commons-annotations version 5.0.2.Final ) in their Java
org.hibernate.common - hibernate-commons-annotations version 5.1.1.Final Maven dependency. How to use hibernate-commons-annotations version 5.1.1.Final in pom.xml?
5.1.1.Final of hibernate-commons-annotations in pom.xml? How to use hibernate... 5.1.1.Final of hibernate-commons-annotations in project by the help of adding... ( org.hibernate.common - hibernate-commons-annotations version 5.1.1.Final ) in their Java
Maven Repository/Dependency: org.hibernate.common | hibernate-commons-annotations
Maven Repository/Dependency of Group ID org.hibernate.common and Artifact ID hibernate-commons-annotations. Latest version of org.hibernate.common:hibernate-commons-annotations dependencies. # Version Release
Maven dependency for org.hibernate - hibernate-annotations version 3.4.0.CR2 is released. Learn to use hibernate-annotations version 3.4.0.CR2 in Maven based Java projects
of hibernate-annotations released The developers of   org.hibernate - hibernate... 2008, the released version of  org.hibernate - hibernate-annotations... and Gradle. How to use  org.hibernate - hibernate-annotations version 3.4.0.CR2
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.1.Final is released. Learn to use hibernate-commons-annotations version 6.0.1.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.1.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.0.Final is released. Learn to use hibernate-commons-annotations version 6.0.0.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.0.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.5.Final is released. Learn to use hibernate-commons-annotations version 6.0.5.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.5.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.0.CR1 is released. Learn to use hibernate-commons-annotations version 6.0.0.CR1 in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.0.CR1. Developer can use
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.0.Beta1 is released. Learn to use hibernate-commons-annotations version 6.0.0.Beta1 in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.0.Beta1. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.3.Final is released. Learn to use hibernate-commons-annotations version 6.0.3.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.3.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.4.Final is released. Learn to use hibernate-commons-annotations version 6.0.4.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.4.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 6.0.2.Final is released. Learn to use hibernate-commons-annotations version 6.0.2.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 6.0.2.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 4.0.5.Final is released. Learn to use hibernate-commons-annotations version 4.0.5.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 4.0.5.Final. Developer can
Maven dependency for org.hibernate.common - hibernate-commons-annotations version 4.0.2.Final is released. Learn to use hibernate-commons-annotations version 4.0.2.Final in Maven based Java projects
of hibernate-commons-annotations released The developers of   org.hibernate.common - hibernate-commons-annotations project have released the latest...; org.hibernate.common - hibernate-commons-annotations library is 4.0.2.Final. Developer can
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
HIBERNATE
HIBERNATE   What is difference between Jdbc and Hibernate

Ads