List of usage examples for org.hibernate.id IdentifierGenerationException IdentifierGenerationException
public IdentifierGenerationException(String msg, Throwable t)
From source file:com.farmafene.commons.hibernate.generators.old.SubSequenceTableGenerator.java
License:Open Source License
/** * {@inheritDoc}/*from w w w.ja v a 2 s .com*/ * * @since 1.0.0 */ public void configure(Type type, Properties props, Dialect dialect) throws MappingException { if (logger.isDebugEnabled()) { logger.debug(props.toString()); } String generatedField = PropertiesHelper.getString(GENERATED_VALUE, props, null); Class<?> entityClass = null; try { entityClass = Class.forName(PropertiesHelper.getString(ENTITY_NAME, props, null)); } catch (ClassNotFoundException e) { throw new IdentifierGenerationException(e.getMessage(), e); } dialectoBBDD = dialect; propertyAccesor = new DirectPropertyAccessor(); identifierType = type; tableName = PropertiesHelper.getString(TARGET_TABLE, props, null); nombreSecuencias = new DataBaseName(PropertiesHelper.getString("catalog", props, null), PropertiesHelper.getString("schema", props, null), PropertiesHelper.getString(SEQUENCE, props, null)); Field[] lista = entityClass.getDeclaredFields(); Field campoClave = null; Field key = null; for (Field f : lista) { if (f.getAnnotation(GeneratedValue.class) != null) { key = f; if (f.getAnnotation(EmbeddedId.class) != null) { tipoEmbedded = true; try { lista = f.getType().getDeclaredFields(); campoClave = f.getType().getDeclaredField(generatedField); } catch (SecurityException e) { throw new IllegalArgumentException(e); } catch (NoSuchFieldException e) { throw new IllegalArgumentException(e); } break; } else if (f.getAnnotation(Id.class) != null) { tipoEmbedded = false; campoClave = f; } else { throw new IllegalArgumentException("Se ha de configurarar Id o EmbeddedId"); } break; } } if (campoClave == null) { throw new IdentifierGenerationException("Debe existir un Campo que generar"); } ArrayList<Field> listaCampos = new ArrayList<Field>(); for (Field f : lista) { if (f.getName().equals(campoClave.getName())) { continue; } if (tipoEmbedded) { if (f.getAnnotation(Column.class) != null) { listaCampos.add(f); } } else { if (f.getAnnotation(Id.class) != null) { listaCampos.add(f); } } } campos = new FieldsGenerador(key, campoClave, listaCampos); if (logger.isDebugEnabled()) { logger.debug("Campos.key: " + campos.getKey()); logger.debug("Campos.target: " + campos.getTarget()); logger.debug("Campos.lista: " + campos.getLista()); logger.debug("Campos.lista: " + campos.getLista().length); } }
From source file:com.farmafene.commons.hibernate.generators.old.SubSequenceTableGenerator.java
License:Open Source License
/** * {@inheritDoc}//from w ww .j a v a 2 s. c o m * * @since 1.0.0 */ public Serializable generate(SessionImplementor sess, Object entity) throws HibernateException { logger.debug("La clase es: " + entity.getClass().getName()); Object[] propiedades = new Object[0]; Serializable key = null; if (campos.getLista().length > 0) { key = (Serializable) propertyAccesor.getGetter(entity.getClass(), campos.getKey().getName()) .get(entity); propiedades = leeParametros(key); } if (campos.getTarget().getName() != null) { try { logger.debug("La clave es: " + ((key == null) ? null : key.getClass().getName())); logger.debug("Numero Propiedades: " + propiedades.length); if (tipoEmbedded) { if (null == propertyAccesor.getGetter(campos.getKey().getType(), campos.getTarget().getName()) .get((Object) key)) { Object id = new WorkInOther(propiedades, logger, dialectoBBDD, nombreSecuencias, campos) .doWorkInNewTransaction(sess); propertyAccesor.getSetter(campos.getKey().getType(), campos.getTarget().getName()) .set((Object) key, id, sess.getFactory()); } else { logger.warn("Ya se ha introducido el valor a generar!!!, utilizando ese valor"); } } else { if (key == null) { Object id = new WorkInOther(propiedades, logger, dialectoBBDD, nombreSecuencias, campos) .doWorkInNewTransaction(sess); key = (Serializable) id; } else { // FIXME !!!, debemos reestructurar la secuencia!!! logger.warn("Ya se ha introducido el valor a generar!!!, utilizando ese valor"); } } } catch (IllegalArgumentException e) { throw new IdentifierGenerationException(e.getMessage(), e); } catch (SecurityException e) { throw new IdentifierGenerationException(e.getMessage(), e); } } return key; }
From source file:com.farmafene.commons.hibernate.generators.SubSequenceTableGenerator.java
License:Open Source License
/** * {@inheritDoc}/*from w ww.ja v a 2 s . c o m*/ * * @since 1.0.0 */ public Serializable generate(SessionImplementor sess, Object entity) throws HibernateException { logger.debug("La clase es: " + entity.getClass().getName()); Object[] propiedades = new Object[0]; Serializable key = null; if (campos.getLista().length > 0) { key = (Serializable) propertyAccesor.getGetter(entity.getClass(), campos.getKey().getName()) .get(entity); propiedades = leeParametros(key); } if (campos.getTarget().getName() != null) { try { logger.debug("La clave es: " + ((key == null) ? null : key.getClass().getName())); logger.debug("Numero Propiedades: " + propiedades.length); if (tipoEmbedded) { if (null == propertyAccesor.getGetter(campos.getKey().getType(), campos.getTarget().getName()) .get((Object) key)) { Object id = new WorkInOther(this, propiedades, logger, dialectoBBDD, nombreSecuencias, campos).doWorkInNewTransaction(sess); propertyAccesor.getSetter(campos.getKey().getType(), campos.getTarget().getName()) .set((Object) key, id, sess.getFactory()); } else { logger.warn( "Ya se ha introducido el valor a generar!!!, utilizando ese valor[" + key + "]"); } } else { if (key == null) { Object id = new WorkInOther(this, propiedades, logger, dialectoBBDD, nombreSecuencias, campos).doWorkInNewTransaction(sess); key = (Serializable) id; } else { // FIXME !!!, debemos reestructurar la secuencia!!! logger.warn( "Ya se ha introducido el valor a generar!!!, utilizando ese valor[" + key + "]"); } } } catch (IllegalArgumentException e) { throw new IdentifierGenerationException(e.getMessage(), e); } catch (SecurityException e) { throw new IdentifierGenerationException(e.getMessage(), e); } } return key; }