-->
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: embedded map
PostPosted: Wed May 22, 2013 6:20 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
I'm facing the task of migrating someone's EJB2 model to EJB3. One of the things that was done was persisting a Map (containing <String, Object>) by serializing it to a binary column. I trying to figure out how to map this in EJB3. The EJB2 definition looks like this:

/**
* @ejb.interface-method
* @ejb.persistence column-name="properties"
*/
public abstract Map getProperties();

I hoped this EJB3 mapping would do the trick:

@Embedded
private Map<String,Object> properties;

But all entities have null instead of a list (which I know is filled).

Any suggestions?


Top
 Profile  
 
 Post subject: Re: embedded map
PostPosted: Wed May 22, 2013 10:12 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
Figured it out myself. For those interested, below are the EJB3 implementations:

@Override
public Map<String, Object> getProperties() {
try {
// deserialize
ObjectInputStream ois = new ObjectInputStream( new ByteInputStream(properties, properties.length) );
Object o = ois.readObject();
MarshalledValue mv = (MarshalledValue)o;
o = mv.get();
HashMap<String, Object> m = (HashMap<String, Object>)o;
return m;
}
catch (IOException e) {
throw new RuntimeException(e);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

@Override
public void setProperties(Map<String, Object> properties) {
try {
// first create a JBoss MarshalledValue
MarshalledValue mv = new MarshalledValue(properties);

// serialize
ByteOutputStream bos = new ByteOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( bos );
oos.writeObject(mv);
oos.flush();
byte[] bs = bos.getBytes();
this.properties = bs;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}


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.