JPA

JPA

I HAVE MADE A PROJECT IN I HAVE MADE ONE - ONE RELATION MY CODE IS ALSO RIGHT FROM MY POINT

OF VIEW. AND WHEN I RUN IT IS GIVING ME THE MESSAGE AS BELOW:::::::

run:
[EL Info]: 2012-02-27 09:42:36.466--ServerSession(26453377)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
[EL Info]: 2012-02-27 09:42:36.965--ServerSession(26453377)--file:/F:/SCHOOL/build/classes/_SCHOOLPU login successful
Object: school.Profile[ profId=107 ] is not a known entity type.
BUILD SUCCESSFUL (total time: 1 second)

THE .JAVA FILES ARE AS FOLLOWS:::::

Student.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package school;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author WAHEGURU
 */
@Entity
@Table(name = "student", catalog = "student", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Student.findAll", query = "SELECT s FROM Student s"),
    @NamedQuery(name = "Student.findByStuId", query = "SELECT s FROM Student s WHERE s.stuId = :stuId"),
    @NamedQuery(name = "Student.findByTeacherId", query = "SELECT s FROM Student s WHERE s.teacherId = :teacherId"),
    @NamedQuery(name = "Student.findByStuName", query = "SELECT s FROM Student s WHERE s.stuName = :stuName"),
    @NamedQuery(name = "Student.findByClass1", query = "SELECT s FROM Student s WHERE s.class1 = :class1")})
public class Student implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Stu_Id", nullable = false)
    private Integer stuId;
    @Basic(optional = false)
    @Column(name = "Teacher_Id", nullable = false)
    private long teacherId;
    @Basic(optional = false)
    @Column(name = "Stu_Name", nullable = false, length = 50)
    private String stuName;
    @Basic(optional = false)
    @Column(name = "Class", nullable = false, length = 10)
    private String class1;

    public Student() {
    }

    public Student(Integer stuId) {
        this.stuId = stuId;
    }

    public Student(Integer stuId, long teacherId, String stuName, String class1) {
        this.stuId = stuId;
        this.teacherId = teacherId;
        this.stuName = stuName;
        this.class1 = class1;
    }

    public Integer getStuId() {
        return stuId;
    }

    public void setStuId(Integer stuId) {
        this.stuId = stuId;
    }

    public long getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(long teacherId) {
        this.teacherId = teacherId;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public String getClass1() {
        return class1;
    }

    public void setClass1(String class1) {
        this.class1 = class1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (stuId != null ? stuId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Student)) {
            return false;
        }
        Student other = (Student) object;
        if ((this.stuId == null && other.stuId != null) || (this.stuId != null && !this.stuId.equals(other.stuId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "school.Student[ stuId=" + stuId + " ]";
    }

}

PROFILE.JAVA

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package school;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author WAHEGURU
 */
@Entity
@Table(name = "profile")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Profile.findAll", query = "SELECT p FROM Profile p"),
    @NamedQuery(name = "Profile.findByProfId", query = "SELECT p FROM Profile p WHERE p.profId = :profId"),
    @NamedQuery(name = "Profile.findByStuId", query = "SELECT p FROM Profile p WHERE p.stuId = :stuId"),
    @NamedQuery(name = "Profile.findByFName", query = "SELECT p FROM Profile p WHERE p.fName = :fName"),
    @NamedQuery(name = "Profile.findByPhone", query = "SELECT p FROM Profile p WHERE p.phone = :phone"),
    @NamedQuery(name = "Profile.findByAddress", query = "SELECT p FROM Profile p WHERE p.address = :address")})
public class Profile implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Prof_Id")
    private Integer profId;
    @Basic(optional = false)
    @Column(name = "Stu_Id")
    private int stuId;
    @Basic(optional = false)
    @Column(name = "F_Name")
    private String fName;
    @Basic(optional = false)
    @Column(name = "Phone")
    private long phone;
    @Basic(optional = false)
    @Column(name = "Address")
    private String address;

    public Profile() {
    }

    public Profile(Integer profId) {
        this.profId = profId;
    }

    public Profile(Integer profId, int stuId, String fName, long phone, String address, Student student) {
        this.profId = profId;
        this.stuId = stuId;
        this.fName = fName;
        this.phone = phone;
        this.address = address;
        this.student=student;
    }

    public Integer getProfId() {
        return profId;
    }

    public void setProfId(Integer profId) {
        this.profId = profId;
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    public String getFName() {
        return fName;
    }             

    public void setFName(String fName) {
        this.fName = fName;
    }

    public long getPhone() {
        return phone;
    }

    public void setPhone(long phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }


    @OneToOne(cascade=CascadeType.ALL)
    private Student student;

    /**
     * @return the person
     */
    public Student getStudent() {
        return student;
    }

    /**
     * @param person the person to set
     */
    public void setStudent(Student student) {
        this.student = student; 
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (profId != null ? profId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Profile)) {
            return false;
        }
        Profile other = (Profile) object;
        if ((this.profId == null && other.profId != null) || (this.profId != null && !this.profId.equals(other.profId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "school.Profile[ profId=" + profId + " ]";
    }


}

SCHOOL.JAVA(MAIN)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package school;


/**
 *
 * @author WAHEGURU
 */




import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Administrator
 */
public class School {     
        public static void main(String arg[]){
        EntityManagerFactory emf=Persistence.createEntityManagerFactory("SCHOOLPU");
        EntityManager em=emf.createEntityManager();
        try{
            EntityTransaction entr=em.getTransaction();
            entr.begin();
            Student stu=new Student();
            stu.setStuId(6);
            stu.setTeacherId(123);
            stu.setStuName("KALA");
            stu.setClass1("VDF");
           /* em.persist(stu);

            entr.commit();
            entr.begin();
     */                
            Profile pf=new Profile();
            pf.setProfId(107);
            pf.setStudent(stu);
            pf.setFName("Faltoo");
            pf.setPhone(54565155);
            pf.setAddress("Khanna");

            em.persist(pf);
            entr.commit();
            System.out.println("Successfully added into database.");
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
        finally{
            em.close();
        }
    }

}

.XML FILE

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="SCHOOLPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>school.Profile</class>
    <class>school.Student</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/student"/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

KINDLY GO THROUGH IT AND LETME KNOW THAT WHAT WERE THE DOUGHTS IN THIS CODE.

View Answers









Related Tutorials/Questions & Answers:
JPA
JPA  HOW CAN I WRITE A SIMPLE PROGRAM IN NETBEANS CONSOLE ON JPA ON CRUD APPLICATION? HOW CAN I START KINDLY HELP ME
JPA
JPA  Sir, I have tried making the jpa application which you have given on this site . But then also I m facing problem in that like : If i make then also it is giving error. If I try to run the application provided by you
Advertisements
JPA
JPA   I HAVE MADE A PROJECT IN I HAVE MADE ONE - ONE RELATION MY CODE IS ALSO RIGHT FROM MY POINT OF VIEW. AND WHEN I RUN IT IS GIVING ME THE MESSAGE AS BELOW::::::: run: [EL Info]: 2012-02-27 09:42:36.466--ServerSession
JPA Framework
JPA Framework  Hi, Can someone tell me about the JPA Framework..., you can get details about the JPA Framework with suitable examples on the below links. http://www.roseindia.net/jpa/eclipsejpaexamples/index.shtml You can visit
Hibernate & JPA
Hibernate & JPA  What is difference between JPA and Hibernate ? Both of them look similar then what is the exact difference between them
JPA Tutorial
JPA Tutorial In this section we will discuss about the Java Persistence API. This section will describe you all the aspects of JPA such as what is JPA, architecture of JPA, features of JPA, JPA entities, entity inheritance JPA, how
Hibernate JPA
In this section, you will learn about JPA with Hibernate
Hibernate 4.3 JPA 2.1
Hibernate 4.3 JPA 2.1  How to create a Java program using Hibernate 4.3 JPA 2.1? I my project I have to use the latest version of Hibernate and JPA... version of Hibernate is 4.3 and JPA is JPA 2.1. My problem is to write
JPA Architecture
JPA Architecture       JPA Architecture: In this section we will discuss the architecture of JPA specification. Java Persistence API or JPA for short is a lightweight, POJO
hibernate session invalid in jpa
hibernate session invalid in jpa  hibernate session invalid in jpa
Version of com.plugback>jpa dependency
List of Version of com.plugback>jpa dependency
Need Jar in the JPA examples
Need Jar in the JPA examples  JPA - tutorial is good, very easy.... and how Hibernates are used in the JPA example? Thnaks Abhijit Das   ...://www.roseindia.net/jpa/ http://www.roseindia.net/jpa/jpacrud/index.shtml http
Hibernate 4.3 and JPA 2.1
Hibernate 4.3 and JPA 2.1  I my project I have to use the the latest version of JPA and Hibernate. I am trying to upgrade the project to use Hibernate 4.3 and JPA 2.1. I am not able to find any example of using Hibernate 4.3
JPA Introduction
JPA Introduction       This section introduces you with the Java Persistence API (JPA). We will learn the benefits of JPA specification. We will also list down the ORM
What is JPA 2.1?
What is JPA 2.1? What are the new features of JPA 2.1? This tutorial will introduce you with the JPA 2.1 specification. You will also learn the new features of the JPA 2.1. Java Persistence API Version 2.1 or JPA 2.1 is defined through
JPA Examples In Eclipse
JPA Examples In Eclipse       In the JPA Examples section we will provide you almost all the examples of JPA framework. This complete JPA tutorials will illustrate you
What do you understand by JPA?
What do you understand by JPA?  What is JPA and how it can be integrated? Thanks   Hi, Check at JPA 2.1 Tutorial. Thanks
JPA delete query - EJB
JPA delete query  Hi, I have an entity InvoiceItems.java. I want to delete all the records from the table. What will be the JPA query to delete all the data. Please let's know. Thanks   Hi, JPA is very
JPA Features
JPA Features       In this section we will discuss about the features of JPA (Java Persistence API). This section will give you an idea about the capabilities of JPA based
Version of com.agapsys>jpa-utils dependency
List of Version of com.agapsys>jpa-utils dependency
Version of com.edugility>jpa-converters dependency
List of Version of com.edugility>jpa-converters dependency
Version of com.gtcgroup>justify-jpa dependency
List of Version of com.gtcgroup>justify-jpa dependency
Version of com.intersult>jpa-support dependency
List of Version of com.intersult>jpa-support dependency
Version of com.intersult>jpa-fix dependency
List of Version of com.intersult>jpa-fix dependency
Version of com.jaxio>jpa-querybyexample dependency
List of Version of com.jaxio>jpa-querybyexample dependency
Hibernate 4.3 and JPA 2.1 support
Hibernate 4.3 and JPA 2.1 support  Hi, Does Hibernate 4.3 provide support for JPA 2.1? I am trying to figure out the Hibernate 4.3 and JPA 2.1... supporting JPA 2.1 completely. You can use the Hibernate 4.3 in JPA 2.1 based project
JPA Native Queries, JPA Native Queries Tutorials
JPA Native Queries       In this section, you will know about the jpa native queries and how to use native query in your JPA application.  JPA Native Queries: JPA native
What is the difference between JPA and Hibernate?
What is the difference between JPA and Hibernate?  Hi, I have seen that both Hibernate and JPA are very popular. Developers are using... between JPA and Hibernate? What a beginner should learn? Thanks   Hi
Hibernate 4.2.4 and JPA 2.1 Example
Hibernate 4.2.4 and JPA 2.1 Example  How to write Hibernate 4.2.4 and JPA 2.1 Example? Thanks   Hi, Hibernate 4.2.4 does not provide support for JPA 2.1, So you can't use it with JPA 2.1. So, if you want to use
Jpa many to many relationship
Jpa many to many relationship  I HAVE Employee, EmpSchedule, EmpSubstitution tables Employee EMP_ID NAME PHONE EmpSchedule EMP_ID Start_date End.... Now how to desing a java jpa classes, i wanted retrieve EmpSubstituion object
JPA Relationship
JPA Relationship          In this section, you will know about the jpa relationship. JPA supports the relationship between entities. There are following types
JPA Crud
JPA Crud       In this section we will show you how to develop simple CRUD application using JPA... the application. This simple JPA CRUD application can be the base for your future
JPA Ordering
JPA Ordering       In this section, you will learn about the JPA Ordering and how to develop JPA application using ordering. JPQL queries can contains ORDER BY clause
JPA Grouping
JPA Grouping       In this section, you will learn about the JPA Grouping and how to use it in your JPA application. The GROUP BY clause is used with SELECT statement to retrieve
Hibernate Native vs Hibernate JPA
Hibernate Native vs Hibernate JPA?   Hibernate is ORM framework which you... provider in JPA applications. Thanks   Hibernate is ORM framework which you... in JPA applications. Thanks
JPA executeUpdate
JPA executeUpdate      ... in your  JPA application. To use executeUpdate() method in your jpa application for executing a jpa UPDATE/DELETE query. This method returns the number of objects
Spring Data jpa with apache phoenix
Spring Data jpa with apache phoenix  Hi, Is there any library from Spring framework for apache phoenix? Thanks   Hi, You can use Spring JDBC template. Thanks
Maven Dependency jpa >> 2.0.0
You should include the dependency code given in this page to add Maven Dependency of com.plugback >> jpa version2.0.0 in your project
JPA 2.1 Tutorial
Learn the new features of JPA 2.1 and understand how to use the new features of JPA 2.1 The Java Persistence API Version 2.1 or simply JPA 2.1 is part of JEE... for using the data from relational database in Java based applications. The JPA allows
Version of com.edugility>jpa-maven-plugin dependency
List of Version of com.edugility>jpa-maven-plugin dependency
Version of com.framework-x>jpa-plugin dependency
List of Version of com.framework-x>jpa-plugin dependency
Version of com.googlecode>jpa-scoped-manager dependency
List of Version of com.googlecode>jpa-scoped-manager dependency
Version of com.montrosesoftware>DbAssist-jpa-commons dependency
List of Version of com.montrosesoftware>DbAssist-jpa-commons dependency
JPA Examples
JPA Examples In this section we will discuss about the examples of JPA. This section will describe you the various examples that will help you create JPA applications. In this page you will find various examples like methods of JPA
Could not open JPA EntityManager for transaction
Could not open JPA EntityManager for transaction  Hi, I am getting following error: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException
maven dependency spring data jpa
maven dependency spring data jpa  Hi, I have to use spring data JPA..., trying to find the latest maven dependency for spring data jpa. What dependency code should I add into the pom.xml file of my project to get spring data jpa
JPA getSingleResult
JPA getSingleResult      ... is your JPA application.  getSingleResult(): This is the method... EntityManagerFactory emf=Persistence.createEntityManagerFactory("jpa"); EntityManager
Which version of Hibernate support JPA 2.1?
Which version of Hibernate support JPA 2.1?  Hi, There is new release of JPA which is JPA 2.1. If you check its features you will find... the Hibernate and the JPA 2.1. Now I have to find out the version of hibernate and create
JPA Training course
JPA Training course JPA stands for Java Persistence API. ... of relational database. At  roseindia.net we provide a 4-day course JPA..._TO_REPLACE_1 Here is the video tutorial of "JPA Training Course": Using
Spring Jpa Hibernate
In this section, you will learn about integrating Spring 3 MVC with Hibernate Jpa using a example

Ads