Win a copy of High Performance Python for Data Analytics this week in the Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Oreilly book example problem

 
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 Friends, I am having some issue while running the client2.java of the example client1.java I could run fine.

I am getting an issue when trying to merge the customer object. Here is the code.


#########################
public static void addPhoneNumbers(EntityManagerFactory factory, Customer cust)
{
Phone phone1 = new Phone();
phone1.setNumber("617-666-6666");
phone1.setType((byte)1);
cust.getPhoneNumbers().add(phone1);

EntityManager manager = factory.createEntityManager();



try
{
System.out.println("############## one ##############");
manager.getTransaction().begin();
manager.persist(phone1);
System.out.println("############## two ##############" + cust.getId());
manager.merge(cust);
System.out.println("############## three ##############");
manager.getTransaction().commit();
System.out.println("############## four ##############");

manager.clear();
Customer custCopy = manager.find(Customer.class, cust.getId());
for (Phone phone : custCopy.getPhoneNumbers())
{
System.out.println("Phone number: " + phone.getNumber());
}
}
finally
{
manager.close();
}

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

I get this output ----------------

Create 1st Customer
Address was also persisted with auto-generated key: 2
Return detached Customer instance: 1
###########3 came out of create customer
############## one ##############
############## two ##############1
Exception in thread "main" 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.Client2.addPhoneNumbers(Client2.java:46)
at com.titan.clients.Client2.main(Client2.java:22)
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)


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

The Customer, Phone and Address clients are same as in the code. I can paste it also though if you want.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the customer ( hope its id is 1) can be loaded using em.find()

If it throws an error, check you database
[ November 20, 2008: Message edited by: Chaminda Amarasinghe ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic