tags:

views:

64

answers:

2

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?

A: 

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.

__roland__
+1  A: 

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.

ChssPly76
you mean I do not use reverse Engineering and make mapping myself?which one is easier annotation or xml mapping?
JGC
As I said, you can use reverse engineering as a starting point, but you'll need to adjust generated mappings to fix your existing domain model. Annotations and XML mappings are roughly equivalent in complexity; if you're using Java 1.5 or later I suggest you go with annotations.
ChssPly76