-->
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.  [ 3 posts ] 
Author Message
 Post subject: Reverge engineering (reveng.xml) and filter-def
PostPosted: Mon May 07, 2012 1:36 pm 
Beginner
Beginner

Joined: Thu Mar 27, 2008 8:49 am
Posts: 27
I need to add a:

Code:
<filter-def name="filterReturnHtDaysSinceDate">
        <filter-param name="paramDate" type="java.lang.String"/>
</filter-def>


into a hbm.xml file (using reveng.xml), and although I have this working directly in the hbm.xml file, I can't find a way to make it work from the revenge.xml file. Looking into the hibernate-tools.jar there is a hbm/filter-def.hbm.ftl template, so it looks like Hibernate Tools may be capable of doing this, but the documentation does not discuss this. Can anyone give me some hints please?


Top
 Profile  
 
 Post subject: Re: Reverge engineering (reveng.xml) and filter-def
PostPosted: Fri May 18, 2012 7:01 pm 
Newbie

Joined: Fri May 18, 2012 5:04 pm
Posts: 4
you should take a look to this post, https://forum.hibernate.org/viewtopic.php?p=2332765
you can use a modified template to generate the hbm with a different layout, but I don't think it is supported to define the filters in the reveng.xml


Top
 Profile  
 
 Post subject: Re: Reverge engineering (reveng.xml) and filter-def
PostPosted: Thu Oct 03, 2013 6:12 am 
Newbie

Joined: Tue Aug 16, 2011 8:38 am
Posts: 3
Hi.
Filter can be added programmatically for example in this way:

import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Set;
import org.hibernate.mapping.Value;


protected void addFilter(final Configuration configuration, final String entityName, final String filterName, final String condition) {
final PersistentClass classMapping = configuration.getClassMapping(entityName);
classMapping.addFilter(filterName, condition);
}

protected void addFilter(final Configuration configuration, final String entityName, final String propertyName, final String filterName, final String condition) {

final PersistentClass classMapping = configuration.getClassMapping(entityName);

final Property property = classMapping.getProperty(propertyName);

Value value = property.getValue();
if (value instanceof Set) {
Set hibernateMappingSet = (Set) value;
hibernateMappingSet.addFilter(filterName, condition);
return;
}

}

If you use Spring, you can extend

import org.springframework.orm.hibernate3.LocalSessionFactoryBean;

and filter can be configured in method

@Override
protected void postProcessConfiguration(Configuration configuration) throws HibernateException {

HashMap<String, Type> parameterTypes = new HashMap<String, Type>();
parameterTypes.put("filterParamXY", IntegerType.INSTANCE); //for exam. integer param
FilterDefinition definition = new FilterDefinition("filterNameXY", ":filterParamXY=user_id", parameterTypes);
configuration.addFilterDefinition(definition);

String entityName = "com.UserXY";
String propertyName = "userId;
String filterName = "filterNameXY";
String condition = ":filterParamXY=user_id"; // it can be redundant - i am not sure - already defined in filter definition
addFilter(configuration, entityName, propertyName, filterName, condition);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.