Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

EJB & JPA Unexpected Results

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have two entities, Client and Telephone





and I'm using the Netbeans generated AbstractFacade handle the persistence. My persistence code is;



If I create a new client with a unique telephone number everything works. However, if I create a new client and reuse an existing persisted
telephone number, I get an exception because the phone number already exists in the database as expected, but the new client is still created in the database. I was expecting a rollback and neither client nor telephone to be persisted.

What am I missing/have I done wrong?

Regards
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your transaction options. It seems you are using a SessionBean, so need to being using a JTA DataSource, but probably are not.

Include your persistence.xml.

 
Glen Divers
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response, persistance.xml is specifying JTA
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ensure that you have defined "jdbc/pembridge" as a JTA enabled DataSource in Glassfish.
 
Glen Divers
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Sutherland wrote:Ensure that you have defined "jdbc/pembridge" as a JTA enabled DataSource in Glassfish.



jdbc/pembridge is defined in terms of a connection pool. There doesn't appear to be any other options. The connection pool is defined as a resource type javax.sql.ConnectionPoolDataSource with a datasource classname of com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.

Glassfish offers alternative resource types of javax.sql.Driver, javax.sql.DataSource and javax.sql.XADataSource. I can't find anything that indicates/mentions JTA.

One odd thing however, Glassfish seems to be creating it's own connection & pool definition. It's created its own connection "pembridge" connnected to pool "mysql_Pembridge_RootPool" which is defined with a resource type of javax.sql.DataSource with a datasource class name of com.mysql.jdbc.jdbc2.optional.MysqlDataSource. If I delete these, they appear to be re-created when I deploy my application, although it never uses this (there's no database userid or password defined for it)

Regards
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the JTA DataSource is the javax.sql.XADataSource one.
 
You didn't tell me he was so big. Unlike 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
    Bookmark Topic Watch Topic
  • New Topic