-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Updating ManyToAny programmtically
PostPosted: Wed Aug 25, 2010 7:22 pm 
Newbie

Joined: Thu Mar 26, 2009 3:00 pm
Posts: 11
Hi,

I have an application which needs to add the concrete classes to a ManyToAny relationship at runtime. Below is the code I'm currently using to do this :

Code:
configuration = new AnnotationConfiguration().configure();
           SessionFactory tempSessionFactory = configuration.buildSessionFactory();
           
           HashMap<ImplicitPolymorphismVariable,List<ImplicitPolymorphismEntry>> implicitPolymorphisimMap = aplosContextListener.getImplicitPolymorphismMap();
           for( ImplicitPolymorphismVariable ipVariable : implicitPolymorphisimMap.keySet() ) {

               if( configuration.getClassMapping( ipVariable.getFullClassName() ) != null ) {
                  RootClass rootClass = configuration.getClassMapping( ipVariable.getFullClassName()  ).getRootClass();
                  Property hibernateProperty = rootClass.getProperty( ipVariable.getVariableName() );
                  
                  Any anyValue = null;
                  if( hibernateProperty.getValue() instanceof Any ) {
                      anyValue = (Any) hibernateProperty.getValue();
                  } else {
                     anyValue = (Any) ((org.hibernate.mapping.Map) hibernateProperty.getValue()).getElement();
                  }
          
                 Map metaMap = anyValue.getMetaValues();
                 if( metaMap == null ) {
                    metaMap = new HashMap();
                 }
                org.hibernate.type.Type metaType = TypeFactory.heuristicType( anyValue.getMetaType() );
                for( ImplicitPolymorphismEntry ipEntry : implicitPolymorphisimMap.get( ipVariable ) ) {
                   Object metaValue = ((DiscriminatorType) metaType).stringToObject( ipEntry.getClassIdentifier() );
                   Mappings mappings = configuration.createMappings();
                   String entityName = HbmBinder.getClassName( ipEntry.getFullClassName(), mappings );
                    metaMap.put( metaValue, entityName );
                }
               }
           }
          
           configuration.buildSessionFactory();


This all seems to work fine at first, it loads out the correct classes from the database and my application works. However when I try to save the ManyToAny relationship it adds in a null value to the contentplaceholder_type field, could someone who works in the source code let me know the missing piece of this jigsaw?


Top
 Profile  
 
 Post subject: Re: Updating ManyToAny programmtically
PostPosted: Thu Aug 26, 2010 8:05 am 
Newbie

Joined: Thu Mar 26, 2009 3:00 pm
Posts: 11
Hi,

I've managed to find the answer, I'd missed a couple of bits. Firstly I was returning the wrong SessionFactoryImpl, I was rebuilding after updating the model but I was returning the old SessionFactoryImpl. Also when I created a new HashMap of MetaValues I was not adding it to the AnyValue. I fixed both of these and it's now working.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.