Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Object Relational Mapping
Exception "javax.persistence.EntityNotFoundException: Unable to find ParkingSpace with 3
prash patil
Ranch Hand
Posts: 40
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Ranchers,
Please help to find out the root cause.
I am working on oneToOne bidirectional mapping.
But while persisting the object got exception
Exception "javax.persistence.EntityNotFoundException: Unable to find ParkingSpace with 3
CREATE TABLE "BGADMIN"."TAB_PARKINGSPACE" ( "PARKINGID" NUMBER NOT NULL ENABLE, "LOT" NUMBER, "LOCATION" VARCHAR2(50 BYTE), CONSTRAINT "TAB_PARKINGSPACE_PK" PRIMARY KEY ("PARKINGID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE ) CREATE TABLE "BGADMIN"."TAB_PROFESSOR" ( "ID" NUMBER NOT NULL ENABLE, "NAME" VARCHAR2(40 BYTE), "SALARY" NUMBER, "PSPACE_ID" NUMBER, CONSTRAINT "TAB_PROFESSOR_PK" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE )
JAVA
classes.
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name="TAB_PROFESSOR") public class Professor { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; @Column(name="name") private String name; @Column(name="salary") private long salary; @OneToOne @JoinColumn(name="PSPACE_ID") private ParkingSpace parkingSpace; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public long getSalary() { return salary; } public void setSalary(long salary) { this.salary = salary; } public ParkingSpace getParkingSpace() { return parkingSpace; } public void setParkingSpace(ParkingSpace parkingSpace) { this.parkingSpace = parkingSpace; } public String toString() { return "Professor id: " + getId() + " name: " + getName() + " with " + getParkingSpace(); } }
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name="TAB_PARKINGSPACE") public class ParkingSpace { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="parkingid") private int id; @Column(name="lot") private int lot; @Column(name="location") private String location; @OneToOne(mappedBy="parkingSpace") private Professor employee; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getLot() { return lot; } public void setLot(int lot) { this.lot = lot; } public String getLocation() { return location; } public void setLocation(String deptName) { this.location = deptName; } public String toString() { return "ParkingSpace id: " + getId() + " lot: " + getLot() + ", location: " + getLocation(); } }
import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; public class MainForOneToOneOracle { public static void main(String[] args) { Professor professor = MainForOneToOneOracle.addProfessor(); System.out.println("Customer id after creation:" + professor.getId()); } /** * Code to add the Professor * @param professor * @return */ private static Professor addProfessor() { // TODO Auto-generated method stub EntityManagerFactory emf = Persistence .createEntityManagerFactory("JPAHibernate-OneToOneOracle"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); Professor professor = new Professor(); professor.setId(100); professor.setName("Prashant Patil"); professor.setSalary(10000); System.out.println("Professor id before creation:" + professor.getId()); //ParkingSpce ParkingSpace parkingSpace = new ParkingSpace(); parkingSpace.setId(8); parkingSpace.setLocation("MySpace"); parkingSpace.setLot(1); professor.setParkingSpace(parkingSpace); em.persist(professor); em.getTransaction().commit(); return professor; } }
Help greatly appriciated.
Regards
PP
prash patil
Ranch Hand
Posts: 40
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
forgot to copy persistent.xml file
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.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_1_0.xsd"> <persistence-unit name="JPAHibernate-OneToOneOracle" transaction-type="RESOURCE_LOCAL"> <class>Professor</class> <class>ParkingSpace</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/> <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.connection.username" value="bgadmin"/> <property name="hibernate.connection.password" value="bgadmin"/> <property name="hibernate.connection.url" value="jdbc:oracle:thin:@punapp510:1521:ATLAS"/> <property name="hibernate.max_fetch_depth" value="3"/> </properties> </persistence-unit> </persistence>
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
result display error
Help. Problem inserting Clob into Oracle 9i
Integrity constraint in Hibernate
Exception while deleting a Entity
How to implement OneToOne entity without explicit id field
More...