[jboss-user] [JBoss Seam] - Cannot instantitate @Embeddable attribute.
infoherlinsys
do-not-reply at jboss.com
Mon Jan 28 13:41:33 EST 2008
Dear Partners.
The following xhtml piece references two attributes
of an Entity-EJB. The first works fine. The second one is
an @Embeddable attribute but it throws an exception:
"Cannot instantiate MonetaryAmount"
Something is wrong.
Attached is the related code.
If appreciate your advice.
Thank you.
Roger Mori.
0)0)0)0)0)
DOB
<s:decorate>
<h:inputText value="#{person.dateOfBirth}"/>
</s:decorate>
Annual Income
<s:decorate>
<h:inputText value="#{person.annualIncome.value}"/>
</s:decorate>
1)1)1)1)1) Action Bean
[...]
@Stateful
@Name("personManager")
public class PersonAction implements PersonManager {
@In (required=false) @Out (required=false)
private Person person;
@PersistenceContext (type=EXTENDED)
private EntityManager em;
// @RequestParameter
Long pid;
public String sayHello () {
em.persist (person);
return "persons";
}
@DataModel
private List fans;
@DataModelSelection
private Person selectedFan;
@Factory("persons")
public void findFans () {
System.out.println("Find called");
fans = em.createQuery("select p from Person p")
.getResultList();
}
public void setPid (Long pid) {
this.pid = pid;
if (pid != null) {
person = (Person) em.find(Person.class, pid);
} else {
person = new Person ();
}
}
public Long getPid () {
return pid;
}
public String delete () {
Person toDelete = em.merge (selectedFan);
em.remove( toDelete );
findFans ();
return null;
}
public String update () {
return "persons";
}
@Remove @Destroy
public void destroy() {}
}
2)2)2)2)2) Entity Bean
[....]
public class Person extends Party {
private Date dateOfBirth ;
[...]
private MonetaryAmount annualIncome;
[...]
@Embedded
@AttributeOverrides ( {
@AttributeOverride(
name = "value",
column = @Column (name = "ANNUAL_INCOME")
),
@AttributeOverride(
name = "currency",
column = @Column (name = "ANUAL_INCOME_CURRENCY", length = 16 )
)
}
)
public MonetaryAmount getAnnualIncome() {
return annualIncome;
}
public void setAnnualIncome(MonetaryAmount annualIncome) {
this.annualIncome = annualIncome;
}
[...]
}
2)2)2)2) Embeddable Attribute
[...]
@Embeddable
public class MonetaryAmount implements Serializable {
//Attributes
private Currency currency;
private BigDecimal value;
//Constructor
MonetaryAmount(){}
public MonetaryAmount(BigDecimal value, Currency currency) {
this.value = value;
this.currency = currency;
}
public MonetaryAmount(BigDecimal value) {
this.value = value;
this.currency = Currency.getInstance(Locale.getDefault());
}
//Accessor Methods
@Column (name = "CURRENCY", length = 16, nullable = false)
public Currency getCurrency() {
return currency;
}
public void setCurrency(Currency currency) {
this.currency = currency;
}
@Column (name = "VALUE", nullable = false )
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
// Common Methods
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MonetaryAmount)) return false;
final MonetaryAmount monetaryAmount = (MonetaryAmount) o;
if (!currency.equals(monetaryAmount.currency)) return false;
if (!value.equals(monetaryAmount.value)) return false;
return true;
}
[...]
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4124154#4124154
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4124154
More information about the jboss-user
mailing list