-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to map "Map<Field, Picklist> fields"
PostPosted: Wed Jun 28, 2006 6:42 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:24 pm
Posts: 30
Location: Brazil
How to map this ?

Code:
public class Field {
  int id;
  String name;
}

public class Picklist {
  String title;
  List<String> itens;
}

public class Worksheet {
  int id;
  Map<Field, Picklist> fields;
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 6:53 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Code:
<class name="Worksheet" ...>
  ...
  <map name="fields" ...>
    <key="id"/>
    <map-key-many-to-many class="Field" column="field_id"/>
    <one-to-many class="Picklist"/>
  </map>
</class>

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 5:47 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:24 pm
Posts: 30
Location: Brazil
This works.

Now, I have an other question.

The map value might be null. When the value is null means that the field has not a picklist. Example: fields.put(field, null). The problem is that when the value is null the field is not returned. How to solve this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 7:37 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Add not-found="ignore" to the one-to-many element.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 5:28 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:24 pm
Posts: 30
Location: Brazil
not-found="ignore" does not work. The result is the same.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 02, 2006 7:17 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There's no alternative. Hibernate won't put null values in a map: you either get no key/value pair, or an exception. You'll have to live with no key/value pair, or change your schema to not use null to mean "no picklist".

You could raise a JIRA issue (or find and existing one?) to add a 'not-found="null"' option to those associations.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 6:35 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:24 pm
Posts: 30
Location: Brazil
I guess that my design was bad. So I have changed to:

Code:
public class Field {
  int id;
  String name;
}

public class Picklist {
  String title;
  List<String> itens;
}

public class WorksheetField {
  Field field;
  Picklist picklist;
}

public class Worksheet {
  int id;
  List<WorksheetField> worksheetFields;
}

Now, all is fine.

Thanks.


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