How to load Map data in YML?

527 views
Skip to first unread message

Federico Tolomei

unread,
Jul 9, 2011, 6:27:40 AM7/9/11
to play-framework
Hello,
I have the following model in standard JPA, based on one from YABE example.

@Entity
public Tag extends Model {
...
@ElementCollection
public Map<Lang, Tag> translations;
...
}

The Lang class has just a "name" field. In the YML file for initial
data I try to load the following tag:

Tag(test):
lang: en
name: Test
translations: {en: mvc, it: play}

(other tags are one from the YABE example). When I run the application
I got the attached error. Is there a particular syntax for the YML
file ? I also tried the following annotation with same effect.

Thank you

Alternativa annotation;
@ElementCollection(targetClass = Tag.class)
@MapKeyClass(Lang.class)
public Map translations;


The error I get:

Caused by: java.lang.RuntimeException: Cannot load fixture
initial-data.yml: org.hibernate.PropertyAccessException: could not get
a field value by reflection getter of models.Lang.id
at play.test.Fixtures.loadModels(Fixtures.java:221)
at play.test.Fixtures.load(Fixtures.java:149)
at Bootstrap.doJob(Bootstrap.java:14)
at play.jobs.Job.doJobWithResult(Job.java:55)
at play.jobs.Job.call(Job.java:157)
... 1 more
Caused by: javax.persistence.PersistenceException:
org.hibernate.PropertyAccessException: could not get a field value by
reflection getter of models.Lang.id
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:798)
at play.db.jpa.JPABase._save(JPABase.java:47)
at play.test.Fixtures.loadModels(Fixtures.java:205)
... 5 more
Caused by: org.hibernate.PropertyAccessException: could not get a
field value by reflection getter of models.Lang.id
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:227)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3875)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3583)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:242)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:121)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeIndex(AbstractCollectionPersister.java:825)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1201)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:345)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795)
... 7 more
Caused by: java.lang.IllegalArgumentException: Can not set
java.lang.Long field play.db.jpa.Model.id to java.lang.String
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)
... 24 more

--
skype: effe.to

Federico Tolomei

unread,
Jul 9, 2011, 6:37:25 AM7/9/11
to play-framework
Langs are defined as follow before everything else:

Lang(en):
lang: en

Lang(it):
lang: it

--
skype: effe.to

Federico Tolomei

unread,
Jul 11, 2011, 9:33:15 AM7/11/11
to play-framework
No one has never used a Map with YML ?

Pascal Voitot Dev

unread,
Jul 11, 2011, 9:43:26 AM7/11/11
to play-fr...@googlegroups.com
with Siena, yes but not with JPA :)

On Mon, Jul 11, 2011 at 3:33 PM, Federico Tolomei <federico...@gmail.com> wrote:
No one has never used a Map with YML ?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Manuel Bernhardt

unread,
Jul 11, 2011, 11:27:52 AM7/11/11
to play-fr...@googlegroups.com
I use this notation for a map and it works fine:

some.Graph(identifier):
parameters:
? entity
: Defect
? graphType
: temporal
? graphLabel
: Defects over time
? temporalField
: created
? xAxis
: DATE
? yAxis
: COUNT

the mapping is:

@ElementCollection(targetClass = String.class)
@MapKeyClass(String.class)
public Map<String, Object> parameters;

Federico Tolomei

unread,
Jul 14, 2011, 6:45:31 AM7/14/11
to play-fr...@googlegroups.com
Thanks for answering. Your YML/Annotation works fine with String. What
if I have objects ?

Something like this:


@ElementCollection(targetClass = Tag.class)
@MapKeyClass(Lang.class)
public Map translations;

The error I posted in first message rise again.

--
skype: effe.to

Manuel Bernhardt

unread,
Jul 14, 2011, 9:47:25 AM7/14/11
to play-fr...@googlegroups.com
did you try defining the objects above in their own block with
identifiers and reference them in the map?

Federico Tolomei

unread,
Jul 14, 2011, 10:34:55 AM7/14/11
to play-fr...@googlegroups.com
On Thu, Jul 14, 2011 at 3:47 PM, Manuel Bernhardt
<bernhard...@gmail.com> wrote:
> did you try defining the objects above in their own block with
> identifiers and reference them in the map?

Yes, I did but still no luck. I get the same error.

Lang(en): &lang_en
lang: en

Lang(it): &lang_it
lang: it

Tag(test): &tag_test
lang: en
name: Test

Tag(play): &tag_play
lang: en
name: Play

Tag(mvc):
lang: en
name: MVC
translations:
? *lang_en
: *tag_test
? *lang_it
: *tag_play


--
skype: effe.to

JavaPlayer

unread,
Jul 14, 2011, 11:21:30 AM7/14/11
to play-framework
I've been trying to do this for months with a lot of different
notations and it never worked.

I think there's something missing in play to be able to do that.
There's a couple of posts about it and no one got an answer. :(

On Jul 14, 10:34 am, Federico Tolomei <federico.tolo...@gmail.com>
wrote:
> On Thu, Jul 14, 2011 at 3:47 PM, Manuel Bernhardt
>

Federico Tolomei

unread,
Jul 14, 2011, 11:23:45 AM7/14/11
to play-fr...@googlegroups.com
I will open a bug report.

--
skype: effe.to

JosefBoukal

unread,
Jul 17, 2011, 4:09:51 PM7/17/11
to play-framework
Hi there,

I have also played with the similar example and do some debugging and
it seems, that I have found a bug in the play.data.binding.Binder
bindInternal method in the following matching pattern:

Pattern p = Pattern.compile("^" + name + suffix + "\\[([^\\]]+)\\](.*)
$");
Matcher m = p.matcher(param);
if (m.matches()) {
...
}

If matches is never called. I don't want to dive into more details and
add some comments to the play bug.
Reply all
Reply to author
Forward
0 new messages