About Question enthuware.oce-ejbd.v6.2.466 :

Moderator: admin

Post Reply
liuyingjie

Re: About Question enthuware.oce-ejbd.v6.2.466 :

Post by liuyingjie »

Hi,

From the result i see the statement
a transaction management type can not be specified for ejb 3.x entiites

but when I did a test on glassfish with code following, I can successfully insert the date into the database based on the structure

servlet--> statefull session bean-->entity, am I understand the statement correctly?


@Entity
@TransactionManagement(TransactionManagementType.BEAN)
public class City implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String country;
private long population;

public City() {
}

public City(String name, String country, long population) {
this.name = name;
this.country = country;
this.population = population;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public long getPopulation() {
return population;
}

public void setPopulation(long population) {
this.population = population;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof City)) {
return false;
}
City other = (City) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
}

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.466 :

Post by admin »

Hello,
Just because an error is not flagged doesn't mean it is valid. The container is probably ignoring it.

Transaction management is NEVER handled by entities. It is handled either by a session bean or servlet or any component that implements the service/DAO layer.

Therefore, @TransactionManagement annotation is not correct on an entity.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests