Reputation: 12997
I have a project which it's domain contain following classes:
Courier
Customer
Food
Order
Customer
PrimitiveElement
ResturantCustomerFacade
ResturantOrderFacade
And My database also has these tables:
Courier
Customer
CustomizedFood
CustomizedPrimitivePrice
FoodType
Order
PrimitiveType
ValueType
and the classes which hibernate makes for above tables has same name of them. Should I use the classes which hibernate makes in my domain although I can not apply my structure of classes because of hibernate class structure. Or I have to use my own domain classes and hibernate classes are just for databse operations?
Upvotes: 1
Views: 613
Reputation: 100686
Hibernate does not make any classes by itself; I'm guessing you're talking about Hibernate Tools that can be used to reverse-engineer your database schema and generate appropriate classes / mappings.
I would strongly advice you against having two sets of classes if you can help it; it usually brings nothing but problems. You should instead write your own mappings using mappings / classes generated by Hibernate Tools as a reference point; in majority of cases you will be able to map your domain classes to your tables with minimal or no changes (e.g. stuff like different class / table or property / column names is easily resolved via appropriate mappings; associations / inheritance is quite flexible, etc...) Here's a link to Hibernate Annotations documentation.
On a separate topic, names like ResturantCustomerFacade
and ResturantOrderFacade
are rather strange for domain objects. If those are indeed part of your model, consider renaming them to RestaurantCustomer
and RestaurantOrder
. OR, if they really are facades, they are not part of domain model and should not (can not) be mapped.
Upvotes: 1
Reputation: 4614
Hibernate should ultimately help you to map your objects to a relational database. If you really encounter difficulties with incompatible types or legacy code, you might consider hiding them (and your hibernate-compatible implementations) behind interfaces.
Upvotes: 0