【问题标题】:how to remove "null id ...entry (don't flush the Session after an exception occurs)"如何删除“null id ...entry(发生异常后不要刷新会话)”
【发布时间】:2014-05-12 03:09:50
【问题描述】:

你好,我是 php 的 web 开发人员,最近迁移到 javaEE。我在 mysql 中创建表。 这是头等舱:

@Entity
@Table(name = "first")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)   
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE,     inclu`enter code here`de = "all")
public class first extends second {

@OneToOne(cascade = CascadeType.ALL)
private second A;

。 . . 这是我的第二节课:

    @Entity
    @Table(name = "second", uniqueConstraints =
    @UniqueConstraint(columnNames = {"feildone", "feildtwo"}))
    public class second implements Serializable {
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "first")
    public static final String FindOne = "findOne";
    @Id
    @GeneratedValue
    Integer id;
    private String feildtwo;
    private String feildone;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date createTime;
    @OneToMany(cascade = CascadeType.ALL)
    public List<Progress> progress = new ArrayList<>();
    private Integer num;

。 . .

【问题讨论】:

  • 你现在有什么问题???
  • @user3484593 告诉我们您的问题到底是什么......或者看看我的解决方案是否适合你......

标签: java mysql hibernate flush


【解决方案1】:

尝试自动生成您的 ID,看看您是否遇到同样的问题

 @Entity
        @Table(name = "second", uniqueConstraints =
        @UniqueConstraint(columnNames = {"feildone", "feildtwo"}))
        public class second implements Serializable {
        @OneToOne(cascade = CascadeType.ALL, mappedBy = "first")
        public static final String FindOne = "findOne";
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO) // try to use auto generate id guess this might help
        Integer id;
        private String feildtwo;
        private String feildone;
        @Temporal(javax.persistence.TemporalType.DATE)
        private Date createTime;
        @OneToMany(cascade = CascadeType.ALL)
        public List<Progress> progress = new ArrayList<>();
        private Integer num;

【讨论】:

  • 这不会改变事情,因为@GeneratedValue 的默认值为GenerationType.AUTO....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-17
  • 2023-04-07
  • 2014-01-26
  • 2014-10-06
  • 2011-07-15
  • 1970-01-01
  • 2012-01-28
相关资源
最近更新 更多