• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hibernate object mapping... design issue?

 
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So this is my first post, as a little background I am very new to this. I haven't gone to school for this but have been working hard on java for a while now. I just passed my Sun Certified Java Programmer certification and try to learn more everyday.

Now I think my problem might be a design issue and hope someone can help me with it.

Project: I am writing a program for a friend and using it as a learning experience. The overall scope of the project is as follow.
Writing a web based application for a dog grooming shop. It keeps track of pets which are tied to owners (customers)
Then for the billable items there are BillableItem objects which belong to Categories.
From invoicing a user would choose an owner, then a pet.
Then a category and a billable item.
All these objects are mapped to mysql with hibernate. They all have individual id's.
All these objects are served to the client (browser) via servlets. All communication to and from the server/client are done via post using xml.

In the invoicing stage I want the user to be able to do a one time edit of an item price, like an override. This should not change the price of the item permanently but for
a one time occurrence only. When the invoice is submitted the invoice should map to a table and each invoice item should map to another table where the
invoice id, item id and cost for that specific invoice is. That way when I load up an invoice from history, it will load up the price of that occurrence and not the price of the
item now.

My invoice object has all it's variables... ie total, tax, paymentType...... and a List<BillableItems> problem is when I send back the info from the client to the servlet and
try to create a billableItem with the ID of the original and the new price and try to save my invoice hibernate freaks (to be expected) because there already is a billableItem
with that ID associated with the session....



I'm sure this is just because of bad design and that there is a clean way around this. The problem is that like I said I'm new to this including hibernate and servlet and jsp and...
well you get the point.

Any help, advice will be gladly accepted and I apologize in advance if I ask what might seem like obvious questions...

Thanks
Marc
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marc,

Can you tell us the tables structure and how they are joined and also your mapping files...
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so here is my table structure: http://pastie.org/861734
Here is Invoice.hbm.xml http://pastie.org/861757
here is the Invoice.java http://pastie.org/861754
Here is the Billableitem.hbm.xml http://pastie.org/861746

Billableitems get sent to client via servlet using XML
They get added to the invoice as requested by the user
Then when the user is happy with the invoice they submit to a servlet via XML. This is all stateless so the
server has no idea what items are there. The server creates an invoice, adds the billableitems in a set
when I try to save the invoice though I get:

SEVERE: Servlet.service() for servlet CreateInvoiceServlet threw exception
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.marc2912.tailWagger.billableItem.Billableitem#9]
.............
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So thinking about this and I came up with this. I shouldn't store the billableitems on an invoice as billableitems. Reason being is that they are not a billableitem but an edited version of one.
I'm wondering if I should somehow just have a list in my invoice that would just keep the billableitem id and the cost but not as an object but two variables. Then when I would load my invoice
from memory i could load the billableitem with the id and then use my setter to set the price on load if different. Since the object itself would not be saved but just those variables hibernate
shouldn't cry foul... maybe?
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marc Cracco wrote:So thinking about this and I came up with this. I shouldn't store the billableitems on an invoice as billableitems. Reason being is that they are not a billableitem but an edited version of one.
I'm wondering if I should somehow just have a list in my invoice that would just keep the billableitem id and the cost but not as an object but two variables. Then when I would load my invoice
from memory i could load the billableitem with the id and then use my setter to set the price on load if different. Since the object itself would not be saved but just those variables hibernate
shouldn't cry foul... maybe?




Sounds good to me...
 
reply
    Bookmark Topic Watch Topic
  • New Topic