[@Entity]
必须与@Id注解 结合使用
否则 No identifier specified for entity:
name 属性
(可选)实体名称。 缺省为实体类的非限定名称。
该名称用于引用查询中的实体。
该名称不能是Java持久性查询语言中的保留字面值。
不与@Table结合的话 表名 默认为 SnakeCaseStrategy(命名策略 )为表名
若使用 name属性 且没有与@Table结合 则表名为 name值的SnakeCaseStrategy(命名策略 )
例如:
@Entity
public class UserEntity{...} 表名 user_entity
@Entity(name="UE")
public class UserEntity{...} 表名 ue
@Entity(name="UsEntity")
public class UserEntity{...} 表名 us_entity
package sun.rain.amazing.javax.anno.domain;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@Data
public class UserEntity {
@Id
private int id;
private String username;
private String email;
public UserEntity(String username, String email) {
this.username = username;
this.email = email;
}
public UserEntity() {
}
}
CREATE TABLE `user_entity` (
`id` int(11) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
package sun.rain.amazing.javax.anno.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Data
@AllArgsConstructor
@Entity(name="UePro")
public class UserEntityProperty {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String username;
private String email;
private String mobile;
public UserEntityProperty(String username, String email, String mobile) {
this.username = username;
this.email = email;
this.mobile = mobile;
}
public UserEntityProperty() {
}
}
CREATE TABLE `ue_pro` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) DEFAULT NULL,
`mobile` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8