@Column注解无效

最近在使用spring boot中的集成jpa的时候,自动创建数据库中的表的时候,不管我的@Column(name="teacherClass")如何注解,最终在数据库中创建出来的字段都是teacher_class,感觉很奇怪,最终经过查询资料得到了一条信息。

Hibernate5的命名策略有过调整,”spring.jpa.hibernate.naming.strategy” 没效果了。

最终在spring boot中的application.properties里面添加了一句话,进行了配置。

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

@Column注解无效_第1张图片

 一下是我的验证的实体代码,最终经过运行程序测试,@Column问题已经解决了!


@Entity
@Table(name="teacher")
public class Teacher implements Serializable {
	
	private static final long serialVersionUID = 3129856851829040003L;
	
	private Integer id;
	private String teacherName;
	private String teacherPhone;
	private String teacherCardId;
	private College college;
	private List  teacherClass = new ArrayList();
	
	@ManyToOne
	@JoinColumn(name="college_c_id")
	public College getCollege() {
		return college;
	}
	public void setCollege(College college) {
		this.college = college;
	}
	
	
	@Id
	@GeneratedValue(generator="a_native")
	@GenericGenerator(name="a_native",strategy="native")
	@Column(name="teacherId")
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(name="teacherName")
	public String getTeacherName() {
		return teacherName;
	}
	public void setTeacherName(String teacherName) {
		this.teacherName = teacherName;
	}
	@Column(name="teacherPhone")
	public String getTeacherPhone() {
		return teacherPhone;
	}
	public void setTeacherPhone(String string) {
		this.teacherPhone = string;
	}
	@Column(name="teacherCardId")
	public String getTeacherCardId() {
		return teacherCardId;
	}
	public void setTeacherCardId(String teacherCardId) {
		this.teacherCardId = teacherCardId;
	}
	
	
	@ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
	@JoinTable(name="teacher_class",
			joinColumns = {@JoinColumn(name = "t_id" ,referencedColumnName = "teacherId")},
		inverseJoinColumns = {@JoinColumn(name = "c_id",referencedColumnName = "gradeId")})
	
	public List getTeacherClass() {
		return teacherClass;
	}
	public void setTeacherClass(List teacherClass) {
		this.teacherClass = teacherClass;
	}
	
	@Override
	public String toString() {
		return "Teacher [id=" + id + ", teacherName=" + teacherName
				+ ", teacherPhone=" + teacherPhone + ", teacherCardId="
				+ teacherCardId + ", college=" + college + ", teacherClass=" + teacherClass + "]";
	}
}

 @Column注解无效_第2张图片

 

你可能感兴趣的:(jpa)