• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with embedded object in hibernate

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The scenario:
1. Customer has homeAddress, workAddress, billingAddress and shippingAddresss
2. Employee has homeAddress1, homeAddress2, hiringOfficeAddress, currentDeploymentAddress
3. Organization has hqAddress
4. All these addresses follow the same format: Street Number, Street Name, Street Type, City, State, Country and additional description (free text field that may contain an apartment unit number, or something else)

So, I may encapsulate properties listed in number 4 in an "Address" class and include it in my Customer, Employee and Organization class. This is the table structure properties of address:
a. StreetType --> id, name (e.g 1 - Street, 2 - Court, 3 - Lane)
b. Country --> country_code, country_name (e.g GBR - Britain, USA - United States of America, AUS - Australia)
c. state --> country_code,state_code,state_name (e.g AUS - VIC - Victoria)
d. city --> country_code,state_code,city_code,city_name (e.g AUS - VIC - MELB - Melbourne)
e. all address fields in customer, employee and organization will consist of these fields : streettype_id (FK to point a), streetNumber (standard independent integer input field), streetName (standard independent nvarchar input field), city_code + state_code + country_code (FK to point d) and finally AdditionalInfo (standard independent nvarchar input field).

For now, I have the following:






and I got java.sql.SQLException: Invalid column name 'streettype'. How should I annotate my classes in this case?
The database structure is already like that (legacy system), so changing the table structure is out of the question.
thanks
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This seems wrong. Isn't StreetType an @Embeddable? Or an @EmbeddedId (since it looks like all/part of the key.) Having it as @Entity implies it is a table. And then you run into trouble with the Address class because it contains a type called StreetType which isn't defined as something that can be embedded.
 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's because Streettype is a separate table, but it can be used in many addresses (work address, shipping address, billing address, etc). This is a master table (standard dropdown)
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's reasonable. I didn't catch that from the description. Now I understand better. I'm not clear on why Address exists different than StreetType though.

Regardless, I think the problem is that you are trying to embed a separate table. Embedding is useful when you have columns in the same table. Like an embedded key. What you have is a relationship. (It appears to be one to one or many to one.) For that you don't use @Embeddable.
 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Streettype is one of the component of address. so address consists of:

2 Hibernate Court, MyCity, MyState 7000, MyCountry

2 --> street number (arbitrary input field)
Hibernate --> street name (arbitrary input field)
Court --> Street type (a dropdown, so user only has limited options --> derived from STREETTYPE table)
MyCity --> the city (also a dropdown --> derived from CITY table)
MyState --> the state (dropdown --> STATES table)
7000 --> post code (arbitrary input field)
MyCountry --> the country (dropdown --> COUNTRY table)

all of these fields are encapsulated in Address which in turn can be used on multiple instances like Employee, Customer or Vendor, etc. That's why I make Address as @Embeddable.
 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any update on this one? if not embeddable, then what technique should be used for this problem?
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic