-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping of class using Hibernate Annotations
PostPosted: Sun May 14, 2006 4:29 pm 
Newbie

Joined: Fri Nov 25, 2005 12:48 pm
Posts: 6
Hello,

Need help !! lol

I have to code an application with Struts and Hibernate. There are the Products and the Customers.
In the Product form, there are groups of multiboxes to specify :
reasons to release the product
caracteristics it has , which makes the product an innovation if it is a machin or a container or other
benefices for environment it can do
benefices for ... and so on

The Class Product of the Model Layer is the following one :

Code:

public class Produit
{
public Produit(){}

private long id;
private String nomFr;
private String nomAng;
private Date dateLancement;
private String typeLancement;
private List<String> raisonsLancement;
private String domaineApplication;
private List<String> caracteresInnovantsContenant;
private List<String> caracteresInnovantsMachine;
private List<String> caracteresInnovantsAutres;
private List<String> beneficesSur;
private List<String> beneficesPratique;
private List<String> beneficesRentable;
private List<String> beneficesEcoCitoyen;
private List<String> beneficesDifferent;
private String descriptifFr;
private String descriptifAng;
private boolean hasPhoto;
private Client client;

/* getters/setters */

}



I know sorry it's in French :)

but globally, I have many properties which are Arrays of String.

As far as the Class Customer is concerned, it's classical (property like id, firstname, lastname ...). A Customer can have many Products and A product is owned by only one customer.

I have to do the mapping by using the annotations.

So a customer will have a Set of product
Then in the class Customer, we'll have annotations such as :

@OneToMany(cascade = CascadeType.ALL)
private List<Produit> produits = new ArrayList<Produit>();

..and so on

so no problem for the Class Customer.


The problem now is I was wondering how to do the mapping of the class Product because it's the first time I do the mapping of a class which has String Arrays as properties. I dunno how to do it (what annotation I have to use ...)and I was also wondering what it will look like physically in the database with such Classes. The table "Product" will have an foreign key references by the "Customer", but what about the String Arrays in the table "Product"...


Please help me ! Any help will be appreciate ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 4:10 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
This is how it is done in XML mappings
Code:
        <set name="strings" table="appsettingnvc" order-by="appsettingnvc_id">
            <key column="appsetting_id"/>
            <element column="value" type="string"/>
        </set>


Look for the equivalent in annotations.


Top
 Profile  
 
 Post subject: Re: Mapping of class using Hibernate Annotations
PostPosted: Mon May 15, 2006 6:07 am 
Newbie

Joined: Fri May 12, 2006 9:48 am
Posts: 14
Location: Toulouse
Hello Danzzz,

Your problem is VERY straight forward and too easy to explain.
You should read the manual 'Hibernate Annotations' in detail !!

Download the bundle (as you probably already did), and go to the doc part. If you use the PDF version of beta10, the exact solution is at the bottom of page 17 (One-to-Many, bidirectional or unidirectional).

I am also a beginner with Hibernate annotations, and totally not an expert.
One does need to go through the manuals first to solve easy problems himself.

HIH


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.