Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oreilly book example problem

 
Arun Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic