views:

51

answers:

0

I am using netbeans to create a simple java app using persistence, and I can query my Entitys using

ReportJpaController rjc = new ReportJpaController();
Report report = new Report(name,value,timestamp);
   List<Report> reports =   rjc.findReportEntities();
     rjc.create(report);

but when I try to call create I get the following error;

java.lang.IllegalArgumentException: Object: mypackage.Report[id=null] is not a known entity type

I have setup a persistence.xml with this;

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
  <persistence-unit name="RemoteDPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/reportd</jta-data-source>
    <class>mypackage.Report</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

id is a auto generated primary key and my entity class looks like this;

@Entity
@Table(name = "REPORT", catalog = "", schema = "ADMIN")
@NamedQueries({
    @NamedQuery(name = "Report.findAll", query = "SELECT r FROM Report r"),
    @NamedQuery(name = "Report.findById", query = "SELECT r FROM Report r WHERE r.id = :id"),
    @NamedQuery(name = "Report.findByAttribute", query = "SELECT r FROM Report r WHERE r.attribute = :attribute"),
    @NamedQuery(name = "Report.findByTimestamp", query = "SELECT r FROM Report r WHERE r.timestamp = :timestamp")})
public class Report implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Column(name = "ATTRIBUTE")
    private String attribute;
    @Lob
    @Column(name = "VALUE")
    private Serializable value;
    @Column(name = "TIMESTAMP")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;

    public Report() {
    }

    public Report(String attribute, Serializable value, Date timestamp) {
        this.attribute = attribute;
        this.value = value;
        this.timestamp = timestamp;
    }

    public Report(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

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

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }

    public Serializable getValue() {
        return value;
    }

    public void setValue(Serializable value) {
        this.value = value;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    @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 Report)) {
            return false;
        }
        Report other = (Report) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "limepepper.Report[id=" + id + "]";
    }

}