开发者社区> 问答> 正文

hibernate注解问题?报错

package com.hn3l.website.entity;

import java.io.Serializable;

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

import org.hibernate.annotations.GenericGenerator;


@Entity
public class Address implements Serializable {

	private static final long serialVersionUID = -8300572285485402602L;
	
	@Id
	@Column(length = 36, nullable = false)
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "guid")
	private String id; // 收获信息id
	private String aPhone; // 手机
	private String aStreet; // 街道
	private String aName; // 收货人
	private int aQPhone; // 区号
	private int aGPhone; // 固话号
	private int aFPhone; // 分机号
	private int aZip; // 邮编
	private int asort; // 收货地址排序
	private int isDef; // 是否默认

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getaPhone() {
		return aPhone;
	}

	public void setaPhone(String aPhone) {
		this.aPhone = aPhone;
	}

	public String getaStreet() {
		return aStreet;
	}

	public void setaStreet(String aStreet) {
		this.aStreet = aStreet;
	}

	public String getaName() {
		return aName;
	}

	public void setaName(String aName) {
		this.aName = aName;
	}

	public int getaQPhone() {
		return aQPhone;
	}

	public void setaQPhone(int aQPhone) {
		this.aQPhone = aQPhone;
	}

	public int getaGPhone() {
		return aGPhone;
	}

	public void setaGPhone(int aGPhone) {
		this.aGPhone = aGPhone;
	}

	public int getaFPhone() {
		return aFPhone;
	}

	public void setaFPhone(int aFPhone) {
		this.aFPhone = aFPhone;
	}

	public int getaZip() {
		return aZip;
	}

	public void setaZip(int aZip) {
		this.aZip = aZip;
	}

	public int getAsort() {
		return asort;
	}

	public void setAsort(int asort) {
		this.asort = asort;
	}

	public int getIsDef() {
		return isDef;
	}

	public void setIsDef(int isDef) {
		this.isDef = isDef;
	}

}

这是代码...项目是用的反向生成数据库表,报错如下:

DEPRECATED : use org.hibernate.id.UUIDGenerator instead with custom org.hibernate.id.UUIDGenerationStrategy implementation <------------- (org.hibernate.id.GUIDGenerator.java:400) 2014-07-21 23:42:28,009 WARN 
Unsuccessful: create table Order (id varchar(36) not null unique, aStreet varchar(255), cid varchar(36) unique, city integer not null, district integer not null, no varchar(255), oDesc longtext, oFhrq datetime, oFkrq datetime, oPayment double precision, oShrq datetime, oState integer not null, oWlgs varchar(100), oXdrq datetime, province integer not null, uid varchar(255), primary key (id)) <------------- (org.hibernate.tool.hbm2ddl.SchemaUpdate.java:454) 2014-07-21 23:42:30,309 ERROR 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order (
        id varchar(36) not null unique,
        aStreet varchar(255),
  ' at line 1 <------------- (org.hibernate.tool.hbm2ddl.SchemaUpdate.java:454) 2014-07-21 23:42:30,310 ERROR


奇怪的是其他表都是用这种主键生成策略生成的 都没有问题 就这个表有问题,大神求解万分感谢....





展开
收起
爱吃鱼的程序员 2020-06-15 19:54:10 2463 0
2 条回答
写回答
取消 提交回答
  • 异常:

    org.hibernate.MappingException: An AnnotationConfiguration instance is required to use

    错误原因: Configuration cfg = new Configuration(); SessionFactory sf = cfg.configure().buildSessionFactory();

    解决方法:

    Hibernate配置文件中,若带有 ,则说明映射类时,采用了Annotation方式。在初始化数控等离子切割机http://www.158cnc.comConfiguation时,应使用AnnoationConfiguration,代码如下: Configuration cfg = new AnnotationConfiguration(); SessionFactory sf = cfg.configure().buildSessionFactory();

    2020-06-16 19:11:52
    赞同 展开评论 打赏
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    既然其他表都可以。估计配置就没问题。我能想到的就是你表名用了关键字。谢谢,嘿嘿马虎了你的order是数据库关键字导致的吧?

    2020-06-15 19:54:26
    赞同 1 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载