This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Persistance issue

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.*;


@Entity
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; }

@OneToOne(cascade={CascadeType.ALL})
@JoinColumn(name="ADDRESS_ID")
public Address getAddress() { return address; }
public void setAddress(Address address) { this.address = address; }

@OneToOne(cascade={CascadeType.ALL})
public CreditCard getCreditCard() { return creditCard; }
public void setCreditCard(CreditCard card) { creditCard = card; }

@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="CUSTOMER_ID")
public Collection<Phone> getPhoneNumbers() { return phoneNumbers; }
public void setPhoneNumbers(Collection<Phone> phones) { this.phoneNumbers = phones; }

@ManyToMany(mappedBy="customers")
public Collection<Reservation> getReservations() { return reservations; }
public void setReservations(Collection<Reservation> reservations) { this.reservations = reservations; }
}


############################

why does it create customer table with these columns

FIRSTNAME
LASTNAME
HASGOODCREDIT

rather than

FIRST_NAME
LAST_NAME
HAS_GOOD_CREDIT


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)
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kumar,
You might need to add the @Column(name="HAS_GOOD_CREDIT") annotation to your setter field... may be...

Bernard
(Also preparing for it!)
 
Arun Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you map the Customer entity in the Address class?
 
Arun Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package com.titan.domain;

import javax.persistence.*;

@Entity
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Bernard.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic