在我的项目中,我需要自动生成每个实体的id,因此我在每个实体中创建了一个序列来完成任务,但不幸的是,每次我点击按钮提交表单时都会显示此问题。
org.postgresql.util.PSQLException: ERREUR: la relation « id_statut_produit_seq » n'existe pas
Position : 17
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:116) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_152]...
这是课程和序列:
@Entity
@Table(name = "STATUT_PRODUITS",schema = "PACKOUT")
public class StatutProduits implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "ID_STATUT_PRODUIT")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idStatutProduit")
@SequenceGenerator(name = "idStatutProduit", sequenceName = "idStatutProduit_SEQ",allocationSize = 1, initialValue =1)
private BigDecimal idStatutProduit;
答案 0 :(得分:1)
看起来你的PostreSQL数据库中没有序列 <tr>
<th>ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if($fetch_data) {
foreach($fetch_data as $row) {
?>
<tr>
<td><?php echo $row->ins_id; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->firstname; ?></td>
<td><a class="btn btn-info" href="<?php echo base_url('Edit_faculty'); ?>">Edit</a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="3">No data found</td>
</tr>
<?php
}
?>
</tbody>
</table>
:
id_statut_produit_seq
但我认为您可以更轻松地获得自动生成的ID:
<强> PostreSQL:强>
-- script to create the sequence
CREATE SEQUENCE id_statut_produit_seq START 1 INCREMENT 1;
<强>类别:强>
-- create the sequence
CREATE SEQUENCE id_statut_produit_seq START 1 INCREMENT 1;
-- create the table
CREATE TABLE statut_produits (
id_statut_produit bigint NOT NULL DEFAULT nextval('id_statut_produit_seq'::regclass)
);