Use mappings from annotations in Hibernate configuration/HQL editor - eclipse

I want to use HQL editor to test queries but it doesn't work. The problem is that we use annotations instead of configuration file. Is it possible to use annotations instead of configuration file as mapping informations? For now after I run query in HQL editor I got this exception org.hibernate.hql.ast.QuerySyntaxExcetion: HomeEntity is not mapped [select h from HomeEntity h].

Zeus is correct. I guess you may be in a situation similar to me ... I spent a couple of nights to figure it out ... well, I guess, you are using Hibernate with Spring. Those "annotatedClass" classes are defined under the Spring configuration (such as applicationContext.xml) but not in hibernate.cfg.xml. Once I defined those classes with in hibernate.cfg.xml, I can see all the entities available under "Configuration" in the Hibernate (tools) Configurations panel and I can use them in the HQL editor.
Hope this help!

Related

How to create a custom annotation processor for Eclipse

I'm trying to create a custom annotation processor that generates code at compilation time (as hibernate-jpamodelgen does). I've looked in the web, and I find custom annotation processors that works with maven, but do nothing when added to the Annotation Processing > Factory Path option. How could I create a processor compatible in this way? I have not found a tutorial that works.
My idea is to, for example, annotate an entity to generate automatically a base DTO, a base mapper, etc that can be extended to use in the final code.
Thank you all
OK, Already found out the problem. The tutorial I hda found out dint't specified that, in order to the compiler to be able to apply the annotation processor, there must be a META-INF/services/javax.annotation.processing.Processor file that contains the qualified class name of the processor (or processors).
I created the file pointing to my processor class, generated the jar and added it to Annotation Processing > Factory Path and all worked correctly.
Just be careful to keep the order of the processors correctly (for example, hibernate model generator claims the classes, so no more generation will be made after it), and change the jar file name each time you want to replace the library (it seems eclipse keeps a cache). These two things have given me a good headache.
Thanks all

How to unkeep or force remove #javax.persistence.Transient annotated methods in JPA entities in ProGuard?

I'm extracting JPA entities into a separate Fat/Uber jar for external system to use.
ProGuard is used through com.github.wvengen:proguard-maven-plugin to shrink all other unused code.
I want to keep all methods in JPA entities except ones annotated by #javax.persistence.Transient annotation. I've found "!transient" for field modifiers in ProGuard rules, but seems that !#javax.persistence.Transient for methods does not work :(
Can I reach the same effect somehow for methods by other way ?
Unfortunately I've not got an answer on this question and was not be able to solve this by ProGuard+MavenPlugin directly, but I've resolved this problem with one additional step before run a ProGuard. I've just used ByteBuddy + Maven plugin on Maven phase before you run ProGuard Maven plugin and it will then optimize/remove the rest unused stuff, see details about byte-buddy instrumentation step here: byte-buddy remove/strip methods

mybatis - how to get rid of mapping file and just use annotations

I was looking at this wonderful mybatis example
http://mybatis.co.uk/index.php/2010/09/mybatis-simple-and-complete-example.html
that uses mostly annotations but was hoping for an #MyBatisDao annotation so I don't need to ever go back to some mapping file and add a line for each dao that I add to the system. I obviously will just use mapping for now but was just curious if there was a way???
You can use the package element to let it scan for your mappers (since 3.1)
MyBatis 3.1 Reference Guide

Doctrine 2.1 abstract entity, validation using annotations

My name is Denis and I really need your help or advice or anything :)
I am developing my project in Zend Framework 1.11 and am using Doctrine 2.1.
I have successfully integrated Doctrine in my ZF project and everything works. I also integrated Gedmo extensions and some my custom extensions.
The problem is with validation. I want to have validation of doctrine entities by using annotations. Because I sometimes need to validate my entities sometimes don't, I want that sort of validation, for example:
$user = new Entity\User; $user->setName('user'); $user->validate();
I don't want to change doctrine generated entities at all, so I won't change setters or use doctrine events for this.#HasLifecycleCallbacks.
I run into example at http://www.spiffyjr.me/2011/07/15/more-doctrine-2-and-zend-framework-integration-goodies/.
I downloaded code but didn't managed to put it in work. I followed instructions from that page, made my entities extend AbstractEntity, but when try to use for example isValid() i recieve following error:
[Semantical Error] The annotation "#Column" in property Bild\Entity\TestTest::$id was never imported. Did you maybe forget to add a "use" statement for this annotation?
I use doctrine annotations without #ORM\, just #, (for example #Column, not #ORM\Column). I even tried to add ORM but no luck it continues to throw errors.
I can recieve metadata for my entity, get field mappings and associating mappings, but when I try to getPropertyAnnotation
// validator annotations
$vAnnotations = self::_getPropertyAnnotation($property, self::ZENDVALIDATION);
var_dump($vAnnotations);die;
I recieve mentioned semantic error.
I tracked the errors down to Doctrine\Common\Annotations\AnnotationReader::getPropertyAnnotations($property); not returning annotations but throwing errors.
What do you think it can be?
It seems like I am not doing something properly but can't figure out what.
So, I need to make abstract entity, make my entities extend it, and make functions to validate my entities by using annotations.
So please, help me with this, if you can. I really need for my project but couldn't find a solution.
Thanks in advance.
Best regards.
The problem is caused by the configuration of the annotation reader. I went through the same problems while integrating the Symfony2 validator service for my Doctrine2 models in ZF1, more on the blog post here http://ssmusoke.wordpress.com/2012/03/04/doctrine-2-day-2-model-validation-using-symfony-validator-service-in-zend-framework/

Error with Groovy AST transformations when cleaning project in Eclipse

I'm trying to work through groovy's Implementing Local AST Transformations tutorial, but whenever I clean my project I get this error in each file that has the #WithLogging annotation in it:
Groovy:Could not find class for Transformation Processor AC.LoggingASTTransformation declared by AC.WithLogging
So you have a package named "AC" that contains both "WithLogging.groovy" and "LoggingASTTransformation.groovy" classes? Does it also contain any classes that implement the "WithLogging" interface?
If so, I'd suggest you move the class(es) that use your annotation to a location outside of the annotation defining package (the default will suffice, for diagnostic purposes) - Order of compilation matters with transformations. See this post on the groovy users mailing list for more on that.
Also try changing the annotation from #WithLogging to #AC.WithLogging.
As far as cleaning with Eclipse is concerned, I had a similar issue and found that I had to make a trivial modification after a clean to any file that contained my annotation. IE, add a space somewhere. Then save the file. This should rebuild everything properly.