Monday, June 12, 2006

Hyperjaxb3 - EJB3

Since I'm no EJB3 expert, I will really need assistance with EJB3 issues. I'll list my current EJB3 problems in this post. I'd be glad if experts comment.

EJB3 roundtrip test case


I need a roundtrip test case for EJB3. I've described what roundtrip test case does in one of the previous posts (unmarshall, save, load, compare).

EJB3 and accessors


I use custom accessors with Hibernate3. First of all, they help with collection fields: JAXB generates no setter, and my custom accessor uses property-based getter and field-based setter to avoid the need to generate a collection setter. Another reason is that custom accessors may take advantage of isSetXXX methods generated by JAXB, for instance to distinguish null and 0 for primitive numeric types. Is it possible to condigure property accessors in EJB3?

Collection of primitive types


How do I map a collection of primitive types (for instance strings) with EJB3? Something like List<String>?

I think it's all for now.

2 Comments:

Blogger Aleksei Valikov said...

Mapping collection of primitive types as a serializable type is not an option, since it's not the desired one-to-many association.
Seems like I'll need to wrap primitive types with entities and map the property as a collection of entity types. Not too elegant. ;(

12:41 PM  
Blogger bdog said...

I believe what you are looking for is @CollectionOfElements.

Ignore the double quotes in the code. This blog was interpreting the type cast as an HTML tag so the quotes had to be added in order to allow the post.

Example:

import org.hibernate.*;
import org.hibernate.annotations.*;

@Entity
@Table(name = "TEST_TABLE")
public class TestDB
{

private String id;
private Set examples;

public TestDB()
{
}

public TestDB(String id)
{
this.id = id;
}

@Id
@Column(name = "U_ID", nullable = false)
public String getId()
{

return this.id;
}

public void setId(String id)
{

this.id = id;
}

@CollectionOfElements
@Column(name="EXAMPLES", nullable=false)
public Set "<"String">"

return this.examples;
}

public void setExamples( Set "<"String">" examples)
{

this.examples = examples;
}
}

8:54 PM  

Post a Comment

<< Home