I am working on a Hibernate issue that includes 2 separate Entity beans, defined separately in their classes:
Please note that there will be more than one StoreServer in the Store - hence the use of the @OneToMany annotation. See Code Snippets as follows:
Store:
@Entity
@Table(name="Store")
public class Store implements Serializable {
private static final long serialVersionUID = 5644190852867691168L;
@Id
@Column(name="STORE_NO", nullable=false)
private int storeNumber;
@Column(name="STORE_NAME", nullable=false)
private String storeName;
@Column(name="STORE_PHONE", nullable=false)
private String storePhone;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name="STORE_NO", insertable=false, updatable=false)
private List<StoreServer> storeServers = new ArrayList<StoreServer>();
StoreServer:
@Entity
@Table(name="Store_Server")
public class StoreServer implements Serializable {
private static final long serialVersionUID = -5410564578856243437L;
@Id
private StoreServerPK storeServerPK;
@Column(name="IP_ADDRESS", nullable=true)
private String ipAddress;
Since StoreServer has a composite primary key, here StoreServerPK:
@Embeddable
public class StoreServerPK implements Serializable {
private static final long serialVersionUID = -1401889029390423604L;
@Column(name="STORE_NO", nullable=false)
protected int storeNumber;
@Column(name="SERVER_NO", nullable=false)
protected String serverNumber;
I'm currently getting the right results, but performance is unacceptably slower. I turned on logging in Hibernate, and I see that for each Storage, a separate SELECT query is created to retrieve the associated StoreServer entries.
SELECT ( 200 ). SELECT StoreServer. : Hibernate ( )?
, , Hibernate , JOIN?