Re: About Question enthuware.oce-ejbd.v6.2.466 :
Posted: Tue Dec 13, 2011 1:27 am
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;
}
}
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;
}
}