Example usage for javax.persistence GenerationType TABLE

List of usage examples for javax.persistence GenerationType TABLE

Introduction

In this page you can find the example usage for javax.persistence GenerationType TABLE.

Prototype

GenerationType TABLE

To view the source code for javax.persistence GenerationType TABLE.

Click Source Link

Document

Indicates that the persistence provider must assign primary keys for the entity using an underlying database table to ensure uniqueness.

Usage

From source file:gov.nih.nci.cacis.xds.authz.domain.AbstractPersistentEntity.java

/**
 * @return entityId
 */
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Long getEntityId() {
    return entityId;
}

From source file:domain.DomainEntity.java

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public int getId() {
    return id;
}

From source file:com.nuevebit.miroculus.mrna.core.MiRNA.java

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "SeqGen-MiRNA")
@TableGenerator(name = "SeqGen-MiRNA", table = "ID_GEN", pkColumnName = "ID_NAME", valueColumnName = "ID_VAL", pkColumnValue = "mirnaId", initialValue = 1, allocationSize = 500)
@Access(AccessType.PROPERTY)//  www  .  j av a2s . c  om
@Override
public Long getId() {
    return super.getId();
}

From source file:com.mycompany.model.AbstractEntity.java

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Integer getId() {
    return id;
}

From source file:it.scoppelletti.programmerpower.security.User.java

/**
 * Restituisce l’id. dell’entità.
 * //  w ww  .  ja  v  a2s. c om
 * @return Valore.
 */
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "sec_user.id")
@Column(name = "id", nullable = false)
public Integer getId() {
    return myId;
}

From source file:de.terrestris.shogun.model.BaseModelInheritance.java

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "ID", nullable = false)
public int getId() {
    return this.id;
}

From source file:com.mmnaseri.dragonfly.metadata.impl.AnnotationTableMetadataResolver.java

private ValueGenerationType determineValueGenerationType(Method method) {
    if (method.isAnnotationPresent(GeneratedValue.class)) {
        final GeneratedValue generatedValue = method.getAnnotation(GeneratedValue.class);
        return generatedValue.strategy().equals(GenerationType.AUTO) ? dialect.getDefaultGenerationType()
                : (generatedValue.strategy().equals(GenerationType.IDENTITY) ? ValueGenerationType.IDENTITY
                        : (generatedValue.strategy().equals(GenerationType.SEQUENCE)
                                ? ValueGenerationType.SEQUENCE
                                : (generatedValue.strategy().equals(GenerationType.TABLE)
                                        ? ValueGenerationType.TABLE
                                        : null)));
    } else {//from www . j  a va  2s . c  om
        return null;
    }
}

From source file:nl.enovation.addressbook.jpa.pojo.Contact.java

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Long getIdentifier() {
    return identifier;
}

From source file:org.emonocot.model.Comment.java

/**
 * @return the id
 */
@Id
@GeneratedValue(generator = "table-hilo", strategy = GenerationType.TABLE)
public Long getId() {
    return id;
}

From source file:org.guzz.builder.JPA2AnnotationsBuilder.java

protected static void addIdMapping(GuzzContextImpl gf, POJOBasedObjectMapping map, SimpleTable st,
        DBGroup dbGroup, String name, Class domainClas, AnnotatedElement element) {
    javax.persistence.Column pc = (javax.persistence.Column) element
            .getAnnotation(javax.persistence.Column.class);
    org.guzz.annotations.Column gc = (org.guzz.annotations.Column) element
            .getAnnotation(org.guzz.annotations.Column.class);

    String type = gc == null ? null : gc.type();
    String column = pc == null ? null : pc.name();

    if (StringUtil.isEmpty(column)) {
        column = name;//from w ww.  ja  v  a 2  s.  com
    }

    TableColumn col = st.getColumnByPropName(name);
    boolean newId = false;

    if (col == null) {
        newId = true;
        col = new TableColumn(st);
    } else {
        log.info("override @Id in the parent class of [" + st.getBusinessName() + "].");
    }

    col.setColName(column);
    col.setPropName(name);
    col.setType(type);
    col.setAllowInsert(true);
    col.setAllowUpdate(true);
    col.setLazy(false);
    map.initColumnMapping(col, null);

    if (newId) {
        st.addPKColumn(col);
    }

    //@Id generator
    javax.persistence.GeneratedValue pgv = (javax.persistence.GeneratedValue) element
            .getAnnotation(javax.persistence.GeneratedValue.class);
    if (pgv == null) {
        pgv = (javax.persistence.GeneratedValue) domainClas
                .getAnnotation(javax.persistence.GeneratedValue.class);
    }

    //If @GeneratedValue is not defined, use auto.
    GenerationType gt = GenerationType.AUTO;
    String generatorName = null;

    if (pgv != null) {
        gt = pgv.strategy();
        generatorName = pgv.generator();
    }

    Properties idProperties = new Properties();
    String igCls;

    if (gt == GenerationType.AUTO) {
        //??guzz@GenericGenerator
        if (StringUtil.notEmpty(generatorName)) {
            GenericGenerator ggg = (GenericGenerator) element.getAnnotation(GenericGenerator.class);
            if (ggg != null && !generatorName.equals(ggg.name())) {
                ggg = null;
            }

            if (ggg == null) {
                //retreive @Id from GlobalContext
                Object g = gf.getGlobalIdGenerator(generatorName);

                //should be GenericGenerator
                if (!(g instanceof GenericGenerator)) {
                    throw new IllegalParameterException("The Id Generator [" + generatorName
                            + "] should be of type @org.guzz.annotations.GenericGenerator. domain class:"
                            + domainClas.getName());
                }

                ggg = (GenericGenerator) g;
            }

            igCls = ggg.strategy();
            Parameter[] ps = ggg.parameters();

            for (Parameter p : ps) {
                idProperties.setProperty(p.name(), p.value());
            }
        } else {
            //nativegeneratordialect?
            igCls = "native";
        }
    } else if (gt == GenerationType.IDENTITY) {
        igCls = "identity";
    } else if (gt == GenerationType.SEQUENCE) {
        igCls = "sequence";

        javax.persistence.SequenceGenerator psg = (javax.persistence.SequenceGenerator) element
                .getAnnotation(javax.persistence.SequenceGenerator.class);
        if (psg == null) {
            Object sg = gf.getGlobalIdGenerator(generatorName);
            Assert.assertNotNull(sg,
                    "@javax.persistence.SequenceGenerator not found for sequenced @Id. domain class:"
                            + domainClas.getName());

            if (sg instanceof SequenceGenerator) {
                psg = (SequenceGenerator) sg;
            } else {
                throw new IllegalParameterException("The Id Generator [" + generatorName
                        + "] should be of type @javax.persistence.SequenceGenerator. domain class:"
                        + domainClas.getName());
            }
        }

        idProperties.setProperty(SequenceIdGenerator.PARAM_SEQUENCE, psg.sequenceName());

        idProperties.setProperty("catalog", psg.catalog());
        idProperties.setProperty("allocationSize", String.valueOf(psg.allocationSize()));
        idProperties.setProperty("initialValue", String.valueOf(psg.initialValue()));

        //we need db_group param, but the JPA won't give us.
    } else if (gt == GenerationType.TABLE) {
        igCls = "hilo.multi";

        TableGenerator pst = (TableGenerator) element.getAnnotation(TableGenerator.class);
        if (pst == null) {
            Object sg = gf.getGlobalIdGenerator(generatorName);
            Assert.assertNotNull(sg,
                    "@javax.persistence.TableGenerator not found for hilo.multi @Id. domain class:"
                            + domainClas.getName());

            if (sg instanceof TableGenerator) {
                pst = (TableGenerator) sg;
            } else {
                throw new IllegalParameterException("The Id Generator [" + generatorName
                        + "] should be of type @javax.persistence.TableGenerator. domain class:"
                        + domainClas.getName());
            }
        }

        idProperties.setProperty("catalog", pst.catalog());
        idProperties.setProperty("schema", pst.schema());
        idProperties.setProperty(TableMultiIdGenerator.TABLE, pst.table());
        idProperties.setProperty(TableMultiIdGenerator.PK_COLUMN_NAME, pst.pkColumnName());
        idProperties.setProperty(TableMultiIdGenerator.PK_COLUMN_VALUE, pst.pkColumnValue());
        idProperties.setProperty(TableMultiIdGenerator.COLUMN, pst.valueColumnName());
        idProperties.setProperty(TableMultiIdGenerator.MAX_LO, String.valueOf(pst.allocationSize()));
        //we need db_group param, but the JPA won't give us.

        idProperties.setProperty("initialValue", String.valueOf(pst.initialValue()));
    } else {
        throw new GuzzException("unknown @javax.persistence.GenerationType:" + gt);
    }

    if ("native".equals(igCls)) {
        igCls = dbGroup.getDialect().getNativeIDGenerator();
    }

    String realClassName = (String) IdentifierGeneratorFactory.getGeneratorClass(igCls);
    Assert.assertNotNull(realClassName, "unknown Id generator:" + igCls);

    IdentifierGenerator ig = (IdentifierGenerator) BeanCreator.newBeanInstance(realClassName);

    if (ig instanceof Configurable) {
        ((Configurable) ig).configure(dbGroup.getDialect(), map, idProperties);
    }

    //register callback for GuzzContext's full starting.
    if (ig instanceof GuzzContextAware) {
        gf.registerContextStartedAware((GuzzContextAware) ig);
    }

    st.setIdentifierGenerator(ig);
}