本文整理汇总了Java中javax.persistence.GeneratedValue类的典型用法代码示例。如果您正苦于以下问题:Java GeneratedValue类的具体用法?Java GeneratedValue怎么用?Java GeneratedValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeneratedValue类属于javax.persistence包,在下文中一共展示了GeneratedValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPid
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Id
@Column(name="PID",length=15)
@Type(type="int")
@GenericGenerator(name="gen",strategy="increment")
@GeneratedValue(generator="gen")
public int getPid() {
return pid;
}
示例2: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "dog")
@TableGenerator(
name = "dog",
table = "sequences",
pkColumnName = "key",
pkColumnValue = "dog",
valueColumnName = "seed"
)
public Long getId() { return id; }
示例3: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Override
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "Id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
示例4: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
/** full constructor */
// Property accessors
@GenericGenerator( name = "generator" , strategy = "identity" )
@Id
@GeneratedValue( generator = "generator" )
@Column( name = "id" , unique = true , nullable = false )
public Integer getId() {
return this.id;
}
示例5: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
/**
* 用户id
* @return
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
示例6: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
示例7: isPostable
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Override
public Optional<Boolean> isPostable(BeanAttributeInformation attributeDesc) {
Optional<Column> column = attributeDesc.getAnnotation(Column.class);
Optional<Version> version = attributeDesc.getAnnotation(Version.class);
if (!version.isPresent() && column.isPresent()) {
return Optional.of(column.get().insertable());
}
Optional<GeneratedValue> generatedValue = attributeDesc.getAnnotation(GeneratedValue.class);
if (generatedValue.isPresent()) {
return Optional.of(false);
}
return Optional.empty();
}
示例8: isPatchable
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Override
public Optional<Boolean> isPatchable(BeanAttributeInformation attributeDesc) {
Optional<Column> column = attributeDesc.getAnnotation(Column.class);
Optional<Version> version = attributeDesc.getAnnotation(Version.class);
if (!version.isPresent() && column.isPresent()) {
return Optional.of(column.get().updatable());
}
Optional<GeneratedValue> generatedValue = attributeDesc.getAnnotation(GeneratedValue.class);
if (generatedValue.isPresent()) {
return Optional.of(false);
}
return Optional.empty();
}
示例9: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
/** @return null. */
@Id
@GeneratedValue
@Column(name = "ID", unique = true, nullable = false)
public Long getId() {
return this.id;
}
示例10: hasAnnotationsOnIdClass
import javax.persistence.GeneratedValue; //导入依赖的package包/类
private static boolean hasAnnotationsOnIdClass(XClass idClass) {
// if(idClass.getAnnotation(Embeddable.class) != null)
// return true;
List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD );
for ( XProperty property : properties ) {
if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) ||
property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) ||
property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) ||
property.isAnnotationPresent( ManyToMany.class )
) {
return true;
}
}
List<XMethod> methods = idClass.getDeclaredMethods();
for ( XMethod method : methods ) {
if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) ||
method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) ||
method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) ||
method.isAnnotationPresent( ManyToMany.class )
) {
return true;
}
}
return false;
}
示例11: columnMap
import javax.persistence.GeneratedValue; //导入依赖的package包/类
private static Map<String, Accessor> columnMap(Class<?> klass, boolean includesGeneratedValue) {
List<Accessor> accessors = new ArrayList<>();
accessors.addAll(getPropertyAccessors(klass));
accessors.addAll(getFieldAccessors(klass));
Map<String, Accessor> result = new HashMap<>();
for (Accessor accessor : accessors) {
String columnName = columnName(accessor);
if (!result.containsKey(columnName)
&& (includesGeneratedValue || accessor.getAnnotation(GeneratedValue.class) == null)) {
result.put(columnName, accessor);
}
}
return result;
}
示例12: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return id;
}
示例13: getId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
@Override
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId()
{
return id;
}
示例14: processId
import javax.persistence.GeneratedValue; //导入依赖的package包/类
private static void processId(
PropertyHolder propertyHolder,
PropertyData inferredData,
SimpleValue idValue,
HashMap<String, IdGenerator> classGenerators,
boolean isIdentifierMapper,
Mappings mappings) {
if ( isIdentifierMapper ) {
throw new AnnotationException(
"@IdClass class should not have @Id nor @EmbeddedId properties: "
+ BinderHelper.getPath( propertyHolder, inferredData )
);
}
XClass returnedClass = inferredData.getClassOrElement();
XProperty property = inferredData.getProperty();
//clone classGenerator and override with local values
HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
//manage composite related metadata
//guess if its a component and find id data access (property, field etc)
final boolean isComponent = returnedClass.isAnnotationPresent( Embeddable.class )
|| property.isAnnotationPresent( EmbeddedId.class );
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
String generatorType = generatedValue != null ?
generatorType( generatedValue.strategy(), mappings ) :
"assigned";
String generatorName = generatedValue != null ?
generatedValue.generator() :
BinderHelper.ANNOTATION_STRING_DEFAULT;
if ( isComponent ) {
generatorType = "assigned";
} //a component must not have any generator
BinderHelper.makeIdGenerator( idValue, generatorType, generatorName, mappings, localGenerators );
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
}
}
示例15: buildGeneratedValue
import javax.persistence.GeneratedValue; //导入依赖的package包/类
private GeneratedValue buildGeneratedValue(Element element) {
Element subElement = element != null ? element.element( "generated-value" ) : null;
if ( subElement != null ) {
AnnotationDescriptor ad = new AnnotationDescriptor( GeneratedValue.class );
String strategy = subElement.attributeValue( "strategy" );
if ( "TABLE".equalsIgnoreCase( strategy ) ) {
ad.setValue( "strategy", GenerationType.TABLE );
}
else if ( "SEQUENCE".equalsIgnoreCase( strategy ) ) {
ad.setValue( "strategy", GenerationType.SEQUENCE );
}
else if ( "IDENTITY".equalsIgnoreCase( strategy ) ) {
ad.setValue( "strategy", GenerationType.IDENTITY );
}
else if ( "AUTO".equalsIgnoreCase( strategy ) ) {
ad.setValue( "strategy", GenerationType.AUTO );
}
else if ( StringHelper.isNotEmpty( strategy ) ) {
throw new AnnotationException( "Unknown GenerationType: " + strategy + ". " + SCHEMA_VALIDATION );
}
copyStringAttribute( ad, subElement, "generator", false );
return AnnotationFactory.create( ad );
}
else {
return null;
}
}