5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【メモ】Hibernateでinsert時にprimary keyでauto incrementを指定している時

Posted at

概要

ERROR [2015-02-27 11:01:38,781] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: ef46ad41b77903a3
! com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hoge.hibernate_sequence' doesn't exist
! at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_20]

こんな感じのエラーが出たので対応したい

コード

hoge.bean.hoge.java
package hoge.bean;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.joda.time.DateTime;

@Entity
@Table(name="hoge_table")
public class HogeTable {	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY) // これをつけて解決
	@Column(name="id")
	private Integer id;
	@Column(name="created")
	private DateTime created;
	@Column(name="modified")
	private DateTime modified;

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

	public DateTime getCreated() {
		return created;
	}
	public void setCreated(DateTime created) {
		this.created = created;
	}
	public DateTime getModified() {
		return modified;
	}
	public void setModified(DateTime modified) {
		this.modified = modified;
	}	
}

元ネタのstackoverflow

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?