wood burning stoves 2.0
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Persistance issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Persistance issue" Watch "Persistance issue" New topic

Persistance issue

Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
Hi Guys I am running this 7.1 example from orielly book

This has the customer bean as below.


package com.titan.domain;

import javax.persistence.*;
import java.util.*;

public class Customer implements java.io.Serializable
private static final long serialVersionUID = 1L;
private int id;
private String firstName;
private String lastName;
private boolean hasGoodCredit;

private Address address;
private Collection<Phone> phoneNumbers = new ArrayList<Phone>();
private CreditCard creditCard;
private Collection<Reservation> reservations = new ArrayList<Reservation>();

@Id @GeneratedValue
public int getId() { return id; }
public void setId(int id) { this.id = id; }

public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }

public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }

public boolean getHasGoodCredit() { return hasGoodCredit; }
public void setHasGoodCredit(boolean flag) { hasGoodCredit = flag; }

public Address getAddress() { return address; }
public void setAddress(Address address) { this.address = address; }

public CreditCard getCreditCard() { return creditCard; }
public void setCreditCard(CreditCard card) { creditCard = card; }

public Collection<Phone> getPhoneNumbers() { return phoneNumbers; }
public void setPhoneNumbers(Collection<Phone> phones) { this.phoneNumbers = phones; }

public Collection<Reservation> getReservations() { return reservations; }
public void setReservations(Collection<Reservation> reservations) { this.reservations = reservations; }


why does it create customer table with these columns


rather than


I am not using any xml file for the mapping and neither COLUMN name overwrite is used in the table using annotation.

I get the following error while running the client1.

Strange part is it is able to create the table but not able to load the customer bean in the second part.


Create 1st Customer
Address was also persisted with auto-generated key: 2
Return detached Customer instance: 1
Show cascade merge()
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.titan.domain.Customer#1]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)
at com.titan.clients.Client1.cascadeMergeAddress(Client1.java:66)
at com.titan.clients.Client1.main(Client1.java:19)
Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.titan.domain.Customer#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1798)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2977)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:393)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:374)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:137)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:193)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:101)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:229)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227)
... 2 more
Caused by: java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
Bernard Adanlessossi

Joined: Oct 05, 2002
Posts: 8
Hi Kumar,
You might need to add the @Column(name="HAS_GOOD_CREDIT") annotation to your setter field... may be...

(Also preparing for it!)
Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
With @Column annotation it creates the columns in the table with the right names but when I run the client it throws precisely same error.

seems like crux of the problem lies somewhere else.
Bernard Adanlessossi

Joined: Oct 05, 2002
Posts: 8
How did you map the Customer entity in the Address class?
Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
package com.titan.domain;

import javax.persistence.*;

public class Address implements java.io.Serializable
private static final long serialVersionUID = 1L;
private int id;
private String street;
private String city;
private String state;
private String zip;

@Id @GeneratedValue
public int getId() { return id;}
public void setId(int id) { this.id = id; }

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 String getState() { return state; }
public void setState(String state) { this.state = state; }

public String getZip() { return zip; }
public void setZip(String zip) { this.zip = zip; }

Thanks again but it is still throwing the same set of errors.
Bernard Adanlessossi

Joined: Oct 05, 2002
Posts: 8
The referenced column in your annotation may be missing... try this
@JoinColumn(name="ADDRESS_ID" referencedColumnName="ID")
where ADDRESS_ID is the foreign key of the address table and ID the address_id in the address table itself.
I agree. Here's the link: http://aspose.com/file-tools
subject: Persistance issue
It's not a secret anymore!