-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using Interfaces And Classes
PostPosted: Wed Jan 21, 2004 6:25 pm 
Newbie

Joined: Sun Jan 18, 2004 5:03 pm
Posts: 12
Location: Texas
I've taken the Order, Product, Customer, LineItem example from the hibernate documentation and translated it to a real project with a struts front end. I'm having difficulties using interfaces rather than implementation classes and I want to know what the best way around this would be.

I have 1 form and 1 action that will just add a Prodcut using hibernate.

The form class, ProductForm, extends ActionForm but implements the Product interface.

The hibernate mapping uses the Prodcut interface and a subclass of ProductImpl.

Now, when ever I try to save the ProdcutForm, casting it to a Prodcut, hibernate will barf and tell me that it doesn't have a mapping for ProductForm.

Does this defeat the whole purpose of using interfaces or am I just using hibernate wrong?

Do I need to have some type of translator that takes the ProductForm and populates a ProductImpl?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 9:44 pm 
Newbie

Joined: Wed Jan 07, 2004 7:59 pm
Posts: 11
Location: Medellon, Colombia
Posting you mapping would be useful.


Anyway, here's and example:

Let Solicitante be an interface
Let ProductoImpl be a class wich implements Solicitante

Code:
<hibernate-mapping>
  <class name="Solicitante" table="SOLICITANTES">
    <id name="codigo" type="string" unsaved-value="null">
      <column name="CODIGO" sql-type="char(16)" not-null="true" />
      <generator class="uuid.hex"/>
    </id>
    <discriminator column="tipo" type="string" force="true" />
    ...
    ...
    <subclass name="SolicitanteImpl" />
  </class>
</hibernate-mapping>


IMHO, you should separate the user interface componentes (struts ActionForms) from your bussines objects.

_________________
Andres Camilo Bustamante
Analista Arquitectura Informaca


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.