javax.el.PropertyNotFoundException
bcdtech Mar 12, 2008 3:03 PMI am not sure if my approach is correct and need some advice from the experts.
I am getting a javax.el.PropertyNotFoundException exception when attempting to access a foreign key relationship that appears to not get loaded when the primary table record is loaded.
My entity class for the station table:
@Entity
@Name("station")
@Table(name = "STATION")
@SequenceGenerator(name = "STATION_SEQ", sequenceName = "STATION_ID_SEQ")
@NamedQueries({@NamedQuery(name = "Station.findById", query = "SELECT s FROM Station s WHERE s.id = :id"),
@NamedQuery(name = "Station.findByStationName", query = "SELECT s FROM Station s WHERE s.stationName = :stationName")
})
public class Station implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "STATION_SEQ")
@Column(name = "ID", nullable = false)
private int id;
@JoinColumn(name = "MARKET_ID", referencedColumnName = "ID")
@ManyToOne
private Market market;
public Station() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Market getMarket() {
return market;
}
public void setMarket(Market market) {
this.market = market;
}
@Override
public String toString() {
return "com.vpiol.media.model.Station[id=" + id + "]";
}
}The entity class for the market table
@Entity
@Name("market")
@Table(name = "MARKET")
@NamedQueries({@NamedQuery(name = "Market.findById", query = "SELECT m FROM Market m WHERE m.id = :id")})
public class Market implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID", nullable = false)
private BigDecimal id;
@Column(name = "MARKET_NAME")
private String marketName;
@OneToMany(mappedBy = "market")
private Collection<Station> stationCollection;
public Market() {
}
public Market(BigDecimal id) {
this.id = id;
}
public BigDecimal getId() {
return id;
}
public void setId(BigDecimal id) {
this.id = id;
}
public String getMarketName() {
return marketName;
}
public void setMarketName(String marketName) {
this.marketName = marketName;
}
@Override
public String toString() {
return "com.vpiol.media.model.Market[id=" + id + "]";
}
}Finally my session bean
@Stateful
@Name("stationManager")
@Restrict("#{identity.loggedIn}")
public class StationBean implements StationLocal {
@PersistenceContext
EntityManager em;
@In(required=false) @Out(required=false)
private String lookupString;
@In(required=false) @Out(required=false)
Station station;
@Begin(join=true)
public String find() {
if (getLookupString() != null ) {
try {
Query q = em.createNamedQuery("Station.findByStationName");
q.setParameter("stationName", getLookupString());
station = (Station) q.getSingleResult();
} catch (Exception e) {
station = new Station();
}
} else {
station = new Station();
}
// when the record is new/undefined set the station name accordingly.
if (station.getId() == 0)
station.setStationName(getLookupString());
return "/station.xhtml";
}
@End
public String save() {
// if this is a new record then we will call the persist
// method to create a new station record, otherwise all the
// merge method to update the record.
if (station.getId() == 0)
em.persist(station);
else
em.merge(station);
station = null;
setLookupString("");
return "/station.xhtml";
}
@End
public String cancel() {
station = null;
return "/home.xhtml";
}
public void setLookupString(String lookupString) {
this.lookupString = lookupString;
}
public String getLookupString() {
return lookupString;
}
@Remove
public void destroy() {
}
}
Finally I have my xhtml file where I use the following:
<h:inputText value="#{station.market.marketName}" />This is where I get the exception.
I get the error even if I have a market record for a station. What am I missing?
Thanks again for your assistance.
Brent