Is there a way to use sql-server like analytic functions in Hibernate?
Something like
select foo from Foo foo where f.x = max(f.x) over (partition by f
Yes you can, but you will need to extend the hibernate dialect like the following:
import org.hibernate.dialect.Oracle10gDialect;
public class ExtendedDialect extends Oracle10gDialect{
public ExtendedDialect()
{
super();
registerKeyword("over");
registerKeyword("partition");
}
}
Once this class is on your classpath, you will need to tell hibernate to use it instead of the original dialect (in this case Oracle10gDialect). I am not sure which frameworks you are using, but in the case of Spring, you can use the following property under the LocalContainerEntityManagerFactoryBean:
Then you can use over and partition in @Formula annotations, @Where annotations and other hibernate features without confusing hibernate.