Cześć! Mam problem z zapisywaniem nowego rekrdu do bazy. Wpisuję oldValue, currentValue, offerCommentText i otrzymuję komunikat o pustej wartości offer_id, który powinien być generowany automatycznie. Załączam mój Offer model, OfferController w którym znajduje się metoda dodająca ofertę oraz komunikat z GlassFisha. Może ktoś z Was może mi doradzić i powiedzieć gdzie popełniłem błąd?
@Entity
@Table(name = "offer")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Offer.findAll", query = "SELECT o FROM Offer o")
, @NamedQuery(name = "Offer.findByOfferId", query = "SELECT o FROM Offer o WHERE o.offerId = :offerId")
, @NamedQuery(name = "Offer.findByCurrentValue", query = "SELECT o FROM Offer o WHERE o.currentValue = :currentValue")
, @NamedQuery(name = "Offer.findByOldValue", query = "SELECT o FROM Offer o WHERE o.oldValue = :oldValue")
, @NamedQuery(name = "Offer.findByOfferCommentText", query = "SELECT o FROM Offer o WHERE o.offerCommentText = :offerCommentText")
, @NamedQuery(name = "Offer.findByOfferCreatingTime", query = "SELECT o FROM Offer o WHERE o.offerCreatingTime = :offerCreatingTime")})
public class Offer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
// @Column(name = "offer_id", nullable = false)
private Integer offerId;
@Basic(optional = false)
@NotNull
@Column(name = "current_value")
private int currentValue;
@Basic(optional = false)
@NotNull
@Column(name = "old_value")
private int oldValue;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 254)
@Column(name = "offer_comment_text")
private String offerCommentText;
@Column(name = "offer_creating_time")
@Temporal(TemporalType.TIMESTAMP)
private Date offerCreatingTime;
@JoinColumn(name = "order_id", referencedColumnName = "order_id")
@ManyToOne(optional = false)
private Order1 orderId;
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
@ManyToOne(optional = false)
private UserAccount userId;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "offerId")
private List<Comment> commentList;
// @OneToMany(cascade = CascadeType.ALL, mappedBy = "offerId")
// private Comment comment;
public Offer() {
}
public Offer(Integer offerId, int currentValue, int oldValue, String offerCommentText, Date offerCreatingTime) {
this.offerId = offerId;
this.currentValue = currentValue;
this.oldValue = oldValue;
this.offerCommentText = offerCommentText;
this.offerCreatingTime = offerCreatingTime;
}
@Named("offerController")
@SessionScoped
public class OfferController implements Serializable {
private String offerCommentText;
private int selectedOfferIndex;
private List<String> offerList;
private Integer offerId;
private int curentValue;
private int oldValue;
private Offer selectedOffer = new Offer();
@Inject
private OfferServiceImpl offerService;
//Gettery, settery
public void addOffer() {
Offer offerToAdd= selectedOffer;
offerToAdd.setOfferCommentText(offerCommentText);
offerToAdd.setOldValue(oldValue);
offerToAdd.setCurrentValue(curentValue);
offerToAdd.setOfferCreatingTime(new Date());
offerService.create(offerToAdd);
}
}
javax.ejb.EJBException: Transaction aborted
(...)
Internal Exception: org.postgresql.util.PSQLException: BŁĄD: pusta wartość w kolumnie "offer_id" narusza ograniczenie wymaganej wartości
Szczegóły: Niepoprawne ograniczenia wiersza (null, null, null, 3, 3, ffff, 2018-11-09 14:50:35.525).
Error Code: 0
Call: INSERT INTO offer (current_value, offer_comment_text, offer_creating_time, old_value, order_id, user_id) VALUES (?, ?, ?, ?, ?, ?)
bind => [6 parameters bound]
Query: InsertObjectQuery(model.Offer[ offerId=null ])
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1611)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:898)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:962)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:631)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2002)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:298)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:377)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:165)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:180)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:489)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:301)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:798)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1786)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1737)
at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:226)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:125)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4207)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1441)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1531)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3168)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:352)
at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:158)
... 78 more
Caused by: org.postgresql.util.PSQLException: BŁĄD: pusta wartość w kolumnie "offer_id" narusza ograniczenie wymaganej wartości
Szczegóły: Niepoprawne ograniczenia wiersza (null, null, null, 3, 3, rrrr, 2018-11-09 15:04:08.908).
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2477)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:424)
at com.sun.proxy.$Proxy316.executeUpdate(Unknown Source)
at com.sun.gjc.spi.base.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:125)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:890)