Using the code below, I was able to create multiple duplicates of the same Station Name, even though the StationName is the primary key.
Code to add data:
Station wmStation = new Station();
wmStation.setStationName(station.getAgentName());
wmStation.setStationDesc(station.getFirstName() + " " + station.getLastName());
wmEmgr.getTransaction().begin();
wmEmgr.persist(wmStation);
wmEmgr.getTransaction().commit();
Entity Class:
package wm.wmdata;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
*
* @author jeick
*/
@Entity
@Table(name = "zSTATION")
@NamedQueries({
@NamedQuery(name = "Station.findByPartSerialNumber", query = "SELECT c FROM Station c WHERE c.stationName = :stationName")})
public class Station implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "STATNAME", nullable = false, length = 50)
private String stationName;
@Basic(optional = false)
@Column(name = "STATDESC", nullable = false, length = 254)
private String stationDesc;
public Station() {
}
public String getStationName() {
return stationName;
}
public void setStationName(String stationName) {
this.stationName = stationName;
}
public String getStationDesc() {
return stationDesc;
}
public void setStationDesc(String stationDesc) {
this.stationDesc = stationDesc;
}
}
|
Try
select * from Station group by stationName having count(stationName )>1;
To see whether there's duplicate row.
If it exists, please check whether there's primary key index on stationName.
|
By having the @Id label on the stationName in the Entity class, shouldn't that identify that column as the primary key?
|
>By having the @Id label on the stationName in the Entity class
If you wish to add a primary key for existent table, you need to run once:
CREATE INDEX stationName ON Station (stationName PRIMARY KEY);
|
Does this apply to Visual FoxPro 9.0, because my VFP admin says that it doesn't need this command. Could you please clarify this for me?
|
That sql is only used by HXTT DBF.
You can create a primary key index in VFP 9.0 through VFP command also. Then HXTT DBF can see it.
|