Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Gurjeet Singh
JPA
0 Answer(s)      2 years and 5 months ago
Posted in : IDE Questions


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.


Advertisement
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
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
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 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
hibernate session invalid in jpa
hibernate session invalid in jpa  hibernate session invalid in jpa
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   .../jpa/ http://www.roseindia.net/jpa/jpacrud/index.shtml http://www.roseindia.net
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 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 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
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
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
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
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 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
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
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
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
JPA getSingleResult
JPA getSingleResult      ... is your JPA application.  getSingleResult(): This is the method...=Persistence.createEntityManagerFactory("jpa"); EntityManager em=emf.createEntityManager
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
Spring Jpa Hibernate
In this section, you will learn about integrating Spring 3 MVC with Hibernate Jpa using a example
JPA-QL Queries
JPA-QL Queries       In this section, we will use the simple JPA-QL query in our JPA application. Here JPA-QL query used with createQuery() method of EntityManager
JPA 2.1 New Features
This section is explaining you the new features of JPA 2.1. The JPA 2.1 specification is coming with many new features and enhancements. The JPA 2.1 aims to make the development of persistence layer easy and maintainable. The JPA 2.1
JPA Named Parameter
JPA Named Parameter       In this section, you will learn how to use JPA Named Parameter in your jpa application. In JPA named parameter is used where you assign names
JPA getResultList Example
JPA getResultList Example   ... the getResultList() method in your JPA application.  getResultList(): This method...=Persistence.createEntityManagerFactory("jpa"); EntityManager em=emf.createEntityManager(); try
JPA Named Queries
JPA Named Queries       In this section, you will know about the JPA Named Queries and how to use in JPA application. @NamedQueries: If you need to use more than one
JPA Positional Parameter
JPA Positional Parameter       In this section, you will learn about the JPA Positional Parameter and how to use in your JPA application. JPA Queries are convenient to pass
JPA Named Parameter List
JPA Named Parameter List       In this section, you will learn how to develop a JPA application using JPA Named Parameter List. This is similar as named parameter
Join problem with JPA Criteria Builder
Join problem with JPA Criteria Builder  I need to make this Query in criteria Builder. At this momento I?´m making it like this: Root<Setting> settingRoot = cr.from(Setting.class); Join<Setting, SettingValue>
JPA update data Example
JPA update data Example       In this section, you know how to update the database data through the jpa... JPA merge() method Follow the following steps
JPA Examples in NetBeans
JPA Examples in NetBeans     ... to run JPA applications. NetBeans IDE provides industry standard features... the business. You can download the JPA example code from the link provides
JPA Count Function
JPA Count Function       In this section, you will learn about the count function of JPA aggregate function. JPA Count function counts all records to database table. JPA Count
JPA update data
JPA update data       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. Create "
JPA update data
JPA update data       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. Create "JPAUpdate"
Hibernate 4.3 and JPA 2.1 Example
How to create Hibernate 4.3 and JPA 2.1 Example program? In this tutorial I will teach you how to write program using the latest Hibernate 4.3 and JPA 2.1... 4.3.x is developed to support the JPA 2.1 specification. You can use
JPA Query with where clause and group by function
JPA Query with where clause and group by function  Any thing wrong in my JPA Query. TypedQuery<RaBdrRating> uQuery = (TypedQuery<RaBdrRating>) entityManager.createQuery("SELECT activePackage,SUM(duration),SUM
Developing JPA CURD Application with Eclipse
Developing JPA CURD Application with Eclipse... will learn how to develop JPA CRUD application in eclipse IDE. Eclipse is one... will learn steps to setup a jpa application in eclipse IDEs. Eclipse
JPA setParameter (Named Parameter)
JPA setParameter (Named Parameter)       In this section, you will learn the JPA Query API's method setParameter as a named parameter. JPA Query API's supports two
JPA Max Function
JPA Max Function       In this section, you will learn how to develop a jpa max function. JPA max function retrieves data from the database table field which
JPA Sub-Queries
JPA Sub-Queries       In this section, you will see how to use sub-queries in your JPA... components in a single query. JPA Sub-queries:  Query query
 

 

 

DMCA.com