Java Code Examples for org.hibernate.proxy.HibernateProxyHelper#getClassWithoutInitializingProxy()
The following examples show how to use
org.hibernate.proxy.HibernateProxyHelper#getClassWithoutInitializingProxy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanContext.java From onedev with MIT License | 6 votes |
public static BeanEditor edit(String componentId, Serializable bean, Collection<String> properties, boolean excluded) { IModel<Serializable> beanModel = new IModel<Serializable>() { @Override public void detach() { } @Override public Serializable getObject() { return bean; } @Override public void setObject(Serializable object) { throw new IllegalStateException(); } }; Class<?> beanClass = HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject()); BeanContext beanContext = new BeanContext(beanClass, properties, excluded); beanModel = beanContext.wrapAsSelfUpdating(beanModel); return beanContext.renderForEdit(componentId, beanModel); }
Example 2
Source File: BeanContext.java From onedev with MIT License | 5 votes |
@SuppressWarnings("unchecked") public static BeanEditor editModel(String componentId, IModel<? extends Serializable> beanModel, Collection<String> properties, boolean excluded) { Class<?> beanClass = HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject()); BeanContext beanContext = new BeanContext(beanClass, properties, excluded); return beanContext.renderForEdit(componentId, (IModel<Serializable>)beanModel); }
Example 3
Source File: AnyType.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException { //TODO: terrible implementation! if ( value == null ) { return "null"; } if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY || !Hibernate.isInitialized( value ) ) { return "<uninitialized>"; } Class valueClass = HibernateProxyHelper.getClassWithoutInitializingProxy( value ); return factory.getTypeHelper().entity( valueClass ).toLoggableString( value, factory ); }
Example 4
Source File: SimpleHibernateProxyHandler.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
public Class<?> getProxiedClass(Object o) { if(o instanceof HibernateProxy) { return HibernateProxyHelper.getClassWithoutInitializingProxy(o); } else { return super.getProxiedClass(o); } }
Example 5
Source File: EntityModel.java From webanno with Apache License 2.0 | 5 votes |
private void analyze(T aObject) { if (aObject != null) { entityClass = HibernateProxyHelper.getClassWithoutInitializingProxy(aObject); String idProperty = null; Metamodel metamodel = getEntityManager().getMetamodel(); EntityType entity = metamodel.entity(entityClass); Set<SingularAttribute> singularAttributes = entity.getSingularAttributes(); for (SingularAttribute singularAttribute : singularAttributes) { if (singularAttribute.isId()) { idProperty = singularAttribute.getName(); break; } } if (idProperty == null) { throw new RuntimeException("id field not found"); } DirectFieldAccessor accessor = new DirectFieldAccessor(aObject); id = (Number) accessor.getPropertyValue(idProperty); } else { entityClass = null; id = null; } }
Example 6
Source File: BeanContext.java From onedev with MIT License | 4 votes |
public static Component viewModel(String componentId, IModel<Serializable> beanModel, Set<String> properties, boolean excluded) { Class<?> beanClass = HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject()); BeanContext editContext = new BeanContext(beanClass, properties, excluded); return editContext.renderForView(componentId, beanModel); }
Example 7
Source File: AbstractQueryImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
private Type guessType(Object param) throws HibernateException { Class clazz = HibernateProxyHelper.getClassWithoutInitializingProxy( param ); return guessType( clazz ); }
Example 8
Source File: HibernateXmlConverter.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @param writer * @param includeHistory * @param session * @throws DataAccessException * @throws HibernateException */ private void writeObjects(final Writer writer, final boolean includeHistory, final Session session, final boolean preserveIds) throws DataAccessException, HibernateException { // Container für die Objekte final List<Object> all = new ArrayList<Object>(); final XStream stream = initXStream(session, true); final XStream defaultXStream = initXStream(session, false); session.flush(); // Alles laden final List<Class< ? >> entities = new ArrayList<Class< ? >>(); entities.addAll(HibernateEntities.instance().getOrderedEntities()); entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities()); for (final Class< ? > entityClass : entities) { final String entitySimpleName = entityClass.getSimpleName(); final String entityType = entityClass.getName(); if (includeHistory == false && entityType.startsWith("de.micromata.hibernate.history.") == true) { // Skip history entries. continue; } List< ? > list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list(); list = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate()); final int size = list.size(); log.info("Writing " + size + " objects"); for (final Iterator< ? > it = list.iterator(); it.hasNext();) { final Object obj = it.next(); if (log.isDebugEnabled()) { log.debug("loaded object " + obj); } Hibernate.initialize(obj); final Class< ? > targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj); final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass); if (classMetadata == null) { log.fatal("Can't init " + obj + " of type " + targetClass); continue; } // initalisierung des Objekts... defaultXStream.marshal(obj, new CompactWriter(new NullWriter())); if (preserveIds == false) { // Nun kann die ID gelöscht werden classMetadata.setIdentifier(obj, null, EntityMode.POJO); } if (log.isDebugEnabled()) { log.debug("loading evicted object " + obj); } if (this.ignoreFromTopLevelListing.contains(targetClass) == false) { all.add(obj); } } } // und schreiben try { writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); } catch (final IOException ex) { // ignore, will fail on stream.marshal() } log.info("Wrote " + all.size() + " objects"); final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy(); stream.setMarshallingStrategy(marshallingStrategy); stream.marshal(all, new PrettyPrintWriter(writer)); }
Example 9
Source File: DomainObject.java From development with Apache License 2.0 | 2 votes |
/** * Returns the domain class of this entity (e.g. Subscription.class). * WARNING: Never use the method entity.getClass(), because JPA might create * dynamic proxy classes during runtime (byte code injection). Always, use * this method instead. */ public static Class<?> getDomainClass(Object entityOrProxy) { return HibernateProxyHelper .getClassWithoutInitializingProxy(entityOrProxy); }