<style>
/* Changing the layout to use less space for mobiles */
@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) {
#email-body { min-width: 30em !important; }
#email-page { padding: 8px !important; }
#email-banner { padding: 8px 8px 0 8px !important; }
#email-avatar { margin: 1px 8px 8px 0 !important; padding: 0 !important; }
#email-fields { padding: 0 8px 8px 8px !important; }
#email-gutter { width: 0 !important; }
}
</style>
<div id="email-body">
<table id="email-wrap" align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#f0f0f0;color:#000000;width:100%;">
<tr valign="top">
<td id="email-page" style="padding:16px !important;">
<table align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border:1px solid #bbbbbb;color:#000000;width:100%;">
<tr valign="top">
<td bgcolor="#3e4c4e" style="background-color:#3e4c4e;color:#ffffff;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;line-height:1;"><img src="https://www.jboss.org/dms/hibernate/images/jira/jiraheader_hibernate.png" alt="" style="vertical-align:top;" /></td>
</tr><tr valign="top">
<td id="email-banner" style="padding:32px 32px 0 32px;">
<table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="width:100%;">
<tr valign="top">
<td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;padding:0;">
<img id="email-avatar" src="https://hibernate.onjira.com/secure/useravatar?ownerId=emmanuel&avatarId=10641" alt="" height="48" width="48" border="0" align="left" style="padding:0;margin: 0 16px 16px 0;" />
<div id="email-action" style="padding: 0 0 8px 0;font-size:12px;line-height:18px;">
<a class="user-hover" rel="emmanuel" id="email_emmanuel" href="https://hibernate.onjira.com/secure/ViewProfile.jspa?name=emmanuel" style="color:#6c797f;">Emmanuel Bernard</a>
commented on <img src="https://hibernate.onjira.com/images/icons/bug.gif" height="16" width="16" border="0" align="absmiddle" alt="Bug"> <a style='color:#6c797f;text-decoration:none;' href='https://hibernate.onjira.com/browse/OGM-208'>OGM-208</a>
</div>
<div id="email-summary" style="font-size:16px;line-height:20px;padding:2px 0 16px 0;">
<a style='color:#6c797f;text-decoration:none;' href='https://hibernate.onjira.com/browse/OGM-208'><strong>Create facility for OGM core and Dialects to receive custom metadata (annotation, programmatic) associated to entities, properties or associations</strong></a>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td id="email-fields" style="padding:0 32px 32px 32px;">
<table border="0" cellpadding="0" cellspacing="0" style="padding:0;text-align:left;width:100%;" width="100%">
<tr valign="top">
<td id="email-gutter" style="width:64px;white-space:nowrap;"></td>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td colspan="2" style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 16px 0;width:100%;">
<div class="comment-block" style="background-color:#edf5ff;border:1px solid #dddddd;color:#000000;padding:12px;"><h3><a name="SomeinfoonJandex"></a>Some info on Jandex</h3>
<p>2012-07-11T08:37:10 <emmanuel> I need your help to better understand your favorite toy: jandex<br/>
2012-07-11T08:37:11 <hardy_> you are alive <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T08:37:14 <emmanuel> do you ahve a few minutes?<br/>
2012-07-11T08:37:15 <hardy_> he he<br/>
2012-07-11T08:37:20 <hardy_> sure<br/>
2012-07-11T08:37:43 <hardy_> how come you are interested in this now?<br/>
2012-07-11T08:37:44 <hardy_> OGM?<br/>
2012-07-11T08:37:58 <emmanuel> yes<br/>
2012-07-11T08:38:17 <emmanuel> So are we forcing people to add the build time jandex task to their persistence archives?<br/>
2012-07-11T08:38:39 <hardy_> no<br/>
2012-07-11T08:39:06 <hardy_> we are building our own index<br/>
2012-07-11T08:39:28 <hardy_> based on the classes, packages etc they provide to the configuration<br/>
2012-07-11T08:40:01 <emmanuel> So you always build it at runtime from scratch<br/>
2012-07-11T08:40:15 <emmanuel> do you "cache" them between application laods?<br/>
2012-07-11T08:40:34 <hardy_> atm it gets build every time<br/>
2012-07-11T08:40:45 <hardy_> but my plan would be to cache the jandex index<br/>
2012-07-11T08:41:04 <hardy_> but that's secondary atm<br/>
2012-07-11T08:42:00 <hardy_> of course it would be nice in the long run to be able to share an index between ORM, Search, etc<br/>
2012-07-11T08:42:07 <hardy_> that would safe parsing time<br/>
2012-07-11T08:44:43 <emmanuel> ok so you're not using Jandex to be faster, but rather for the API<br/>
2012-07-11T08:44:44 <emmanuel> and you don't share the same index as the app server, which I thought was the idea to speed up load time<br/>
2012-07-11T08:45:35 <emmanuel> What did you like about Jandex parsing wise that you did not like in our current parser?<br/>
2012-07-11T08:45:44 <emmanuel> s/current/old/<br/>
2012-07-11T08:45:53 <emmanuel> I am poking you to get an idea<br/>
2012-07-11T08:45:58 <emmanuel> not judging here<br/>
2012-07-11T08:46:09 <hardy_> right, I am mainly after the api<br/>
2012-07-11T08:46:18 <hardy_> but in the long run also about sharing the index<br/>
2012-07-11T08:46:33 <hardy_> the api has a couple of advantages imo<br/>
2012-07-11T08:46:51 <hardy_> #1 there is a clear separation of annotation discovery and annotation processing now<br/>
2012-07-11T08:47:09 <hardy_> in our current code this is always mixed since we do both things at the same time<br/>
2012-07-11T08:47:34 <hardy_> jandex is giving you the annotation discovery and build what I call a Annotation Repository<br/>
2012-07-11T08:48:00 <hardy_> having such a repository allows to to process data in different ways<br/>
2012-07-11T08:48:37 <hardy_> think about global annotations<br/>
2012-07-11T08:48:44 <hardy_> take AnalyzerDef from Search<br/>
2012-07-11T08:48:58 <hardy_> they are application scoped and I don't care where they are defined<br/>
2012-07-11T08:49:06 <hardy_> I just want to know if and how many exist<br/>
2012-07-11T08:49:31 <hardy_> in the "old" way I have to still iterate the configured entities and for each entity do the check<br/>
2012-07-11T08:49:59 <hardy_> with jandex I say: jandex.getAnnotation(AnalyzerDef.class) and I get all the annotations<br/>
2012-07-11T08:50:16 <emmanuel> Jandex gives you an API to look for a given annotation directly?<br/>
2012-07-11T08:50:17 <hardy_> I can do this processing outside my entity processing<br/>
2012-07-11T08:50:20 <emmanuel> I have not seen that<br/>
2012-07-11T08:50:21 <hardy_> yes<br/>
2012-07-11T08:50:36 <hardy_> one sec<br/>
2012-07-11T08:51:00 <emmanuel> <a href="https://github.com/jbossas/jandex/blob/master/src/main/java/org/jboss/jandex/Index.java">https://github.com/jbossas/jandex/blob/master/src/main/java/org/jboss/jandex/Index.java</a><br/>
2012-07-11T08:52:01 <hardy_> List<AnnotationInstance> getAnnotations(DotName annotationName)<br/>
2012-07-11T08:52:06 <hardy_> in Index<br/>
2012-07-11T08:52:27 <hardy_> you just provide the dot name of the annotation you are after and you get a list of them<br/>
2012-07-11T08:52:55 <hardy_> the alternative is to go via the ClassInfo<br/>
2012-07-11T08:53:43 <emmanuel> CAn you say, give me all the classes hosting annotation A?<br/>
2012-07-11T08:53:45 <hardy_> that is more the reflection type of processing (which you also need of course)<br/>
2012-07-11T08:54:01 <emmanuel> Or give me all the classes hosting annotations which are anntated with @Stereotype?<br/>
2012-07-11T08:54:39 <emmanuel> Alternatively can you go from AnnotationInstance to the reflection info releated to where tha nnotationInstance is hosted?<br/>
2012-07-11T08:54:55 <hardy_> that's what getAnnotations does<br/>
2012-07-11T08:55:08 <hardy_> the AnnotationInstance contains AnnotationTarget<br/>
2012-07-11T08:55:32 <hardy_> which gives you access to the ClassInfo, MethodInfo or FieldInfo<br/>
2012-07-11T08:55:47 <emmanuel> got it, I missed that link<br/>
2012-07-11T08:55:58 <hardy_> np<br/>
2012-07-11T08:56:05 <emmanuel> (btw, I looked for doc but ended up scanning the code, did I miss something?)<br/>
2012-07-11T08:56:19 <hardy_> nope, the code is probably the best place to look<br/>
2012-07-11T08:56:34 <hardy_> I don't think they have a project site or something like this<br/>
2012-07-11T08:56:41 <hardy_> there is the code and the issue tracker<br/>
2012-07-11T08:56:54 <emmanuel> ok<br/>
2012-07-11T08:57:47 <hardy_> basically the API allows you to write at times cleaner code<br/>
2012-07-11T08:57:52 <hardy_> and less convoluted<br/>
2012-07-11T08:58:09 <hardy_> just because you are having multiple ways to read/process the annotations<br/>
2012-07-11T08:58:16 <emmanuel> Do you use getKnownDirectSubclasses<br/>
2012-07-11T08:58:33 <emmanuel> (yes I see that it has a couple of powerful APIs)<br/>
2012-07-11T08:59:05 <hardy_> I think the issue with this method is that only subclasses which are annotated appear there<br/>
2012-07-11T08:59:46 <hardy_> which might be enough in most cases<br/>
2012-07-11T09:00:02 <hardy_> to be honest I am not sure whether it is used atm or not<br/>
2012-07-11T09:00:06 <emmanuel> oh really<br/>
2012-07-11T09:00:17 <emmanuel> so they filter out non annotated types?<br/>
2012-07-11T09:01:12 <hardy_> wrong, it does to have to be annotated<br/>
2012-07-11T09:01:34 <emmanuel> you mena right then <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:01:41 <hardy_> but it has to be found during the scanning process<br/>
2012-07-11T09:01:44 <emmanuel> ah hold on<br/>
2012-07-11T09:01:47 <hardy_> read the jaadoc <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:01:52 <emmanuel> right ok got you<br/>
2012-07-11T09:02:05 <emmanuel> which one<br/>
2012-07-11T09:02:08 <emmanuel> <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:03:09 <emmanuel> So with XML or say a programmatic API, how do you do it?<br/>
2012-07-11T09:03:20 <emmanuel> Do you have some kind of merger impl?<br/>
2012-07-11T09:03:20 <hardy_> that's another nice thing imo<br/>
2012-07-11T09:03:31 <hardy_> I never liked the Class vs XClass thing<br/>
2012-07-11T09:03:49 <emmanuel> hardy_: I'll come to that later <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:04:33 <hardy_> the beauty of Jandex is that once you have the index you don't deal with java.lang.annotation.Annotation anymore<br/>
2012-07-11T09:04:56 <hardy_> you are dealing with ClassInfo and AnnotationInstance<br/>
2012-07-11T09:05:05 <emmanuel> so do you build the Jandex model offf the XML or the programmatc API?<br/>
2012-07-11T09:05:10 <hardy_> so all you have to do is to create AnnotationInstnaces<br/>
2012-07-11T09:05:13 <hardy_> right<br/>
2012-07-11T09:05:33 <emmanuel> so you ahve sort of a fork of IndexReader?<br/>
2012-07-11T09:05:34 <hardy_> Strong wrote the xml processing for ORM<br/>
2012-07-11T09:06:15 <emmanuel> I guess that would be more Indexer<br/>
2012-07-11T09:06:50 <hardy_> I think we just create the AnnotationInstances and then create a new Index by creating a merged annotations map<br/>
2012-07-11T09:06:57 <hardy_> check the constructor of Index<br/>
2012-07-11T09:07:39 *** sannegrinovero has joined #hibernate-dev<br/>
2012-07-11T09:08:30 <hardy_> Index.create in fact<br/>
2012-07-11T09:09:01 <emmanuel> k<br/>
2012-07-11T09:09:36 <emmanuel> If you ahve a pointer to stliu's code I'll check it out<br/>
2012-07-11T09:09:52 <hardy_> it is on the metamodel branch<br/>
2012-07-11T09:10:07 <hardy_> the package org.hibernate.metamodel.internal.source.annotations.xml<br/>
2012-07-11T09:10:21 <emmanuel> Other question, do you keep the index in memory? Or do you discard it after the init phase?<br/>
2012-07-11T09:10:47 <hardy_> it is not needed anymore once everything is processes<br/>
2012-07-11T09:10:52 <hardy_> no need to keep it around<br/>
2012-07-11T09:11:00 <emmanuel> And have you measured the overhead of the Index compared to having the class model only which we need anyways for Hibernate?<br/>
2012-07-11T09:11:11 <emmanuel> OK, well Search would need it longer <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/sad.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:11:24 <hardy_> why?<br/>
2012-07-11T09:11:36 <emmanuel> because the factory is now mutable<br/>
2012-07-11T09:11:44 <emmanuel> you can add entities<br/>
2012-07-11T09:11:51 <emmanuel> that was required for Infinispan<br/>
2012-07-11T09:12:11 <emmanuel> Ask sannegrinovero it was not a walk in the park<br/>
2012-07-11T09:12:28 <hardy_> do I need to keep everything just for that<br/>
2012-07-11T09:12:59 <emmanuel> AFAIR yes<br/>
2012-07-11T09:13:14 <emmanuel> So my final question is about the API and code maintainability<br/>
2012-07-11T09:13:34 <emmanuel> Since you are decorrelated from Java's reflection API and the annotations as well<br/>
2012-07-11T09:13:35 <sannegrinovero> we do add new entities at runtime, but of course that doesn't happen very often. We could consider reloading the disk-stored index if need arises?<br/>
2012-07-11T09:14:02 <emmanuel> how do you quickly find the Jandex related reading calls corresponding to a specific annotation say @Columns<br/>
2012-07-11T09:14:06 <hardy_> adding an unrelated entity seems to be something which should be possible w/o processing everything again<br/>
2012-07-11T09:14:09 <hardy_> anyways<br/>
2012-07-11T09:14:43 <hardy_> sannegrinovero: right<br/>
2012-07-11T09:14:56 <emmanuel> hardy_: because my concern is that with these DotNames thingy, we back in String code's stone age<br/>
2012-07-11T09:15:25 <emmanuel> Likewise, when the annotation structure changes are you warned in any way?<br/>
2012-07-11T09:15:46 <hardy_> right, the dot name thing is one of the issues I had w/ jandex initially as well<br/>
2012-07-11T09:15:56 <hardy_> in ORM we created a constant file<br/>
2012-07-11T09:16:19 <hardy_> i think that works ok and it is actually a nice place to get an overview over all annotations<br/>
2012-07-11T09:16:20 <hardy_> one sec<br/>
2012-07-11T09:17:10 <hardy_> <a href="https://github.com/hibernate/hibernate-orm/blob/metamodel/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPADotNames.java">https://github.com/hibernate/hibernate-orm/blob/metamodel/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPADotNames.java</a><br/>
2012-07-11T09:17:34 <hardy_> there is one other thing which sucks<br/>
2012-07-11T09:17:46 <hardy_> there is no access to the default values of an annotation<br/>
2012-07-11T09:18:28 <emmanuel> ok so when it reads it, it returns null or the default primitive value instead of the default value?<br/>
2012-07-11T09:18:44 <hardy_> <a href="https://issues.jboss.org/browse/JANDEX-5">https://issues.jboss.org/browse/JANDEX-5</a><br/>
2012-07-11T09:18:45 <jbossbot> jira <span class="error">[JANDEX-5]</span> Default values for annotation attributes ignored <span class="error">[Resolved (Won't Fix) Bug, Major, Jason Greene]</span> <a href="https://issues.jboss.org/browse/JANDEX-5">https://issues.jboss.org/browse/JANDEX-5</a><br/>
2012-07-11T09:19:02 <hardy_> in ORM we worked around this with a JandexHelper<br/>
2012-07-11T09:19:45 <hardy_> <a href="https://github.com/hibernate/hibernate-orm/blob/metamodel/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java">https://github.com/hibernate/hibernate-orm/blob/metamodel/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java</a><br/>
2012-07-11T09:20:04 <hardy_> for me it is the only bitter pill in the API<br/>
2012-07-11T09:21:11 <hardy_> but as you can see in the issue it is just not possible to get to the information by just looking the class file. a shame really<br/>
2012-07-11T09:23:50 <emmanuel> ok<br/>
2012-07-11T09:24:37 <emmanuel> It seems your logic won't work for<br/>
2012-07-11T09:24:38 <emmanuel> @interface Pool {
2012-07-11T09:24:38 <emmanuel> int size() default 10;
2012-07-11T09:24:38 <emmanuel> }<br/>
2012-07-11T09:24:43 <emmanuel> yu will get 0out of it <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/sad.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:25:09 <hardy_> ?<br/>
2012-07-11T09:25:26 <emmanuel> At least Jandex should have a isdefault() on AnnotationValue or whatever the type they use<br/>
2012-07-11T09:25:39 <emmanuel> If I use @Pool()<br/>
2012-07-11T09:25:44 <emmanuel> the value is not stored<br/>
2012-07-11T09:25:50 <emmanuel> so jandex don't see it<br/>
2012-07-11T09:25:57 <emmanuel> but since they return primitives<br/>
2012-07-11T09:26:02 <emmanuel> they will return the default value ie 0<br/>
2012-07-11T09:26:07 <emmanuel> instead of the expected 10<br/>
2012-07-11T09:26:34 <hardy_> you get a AnnotationValue back<br/>
2012-07-11T09:26:48 <hardy_> and if there is no value specified you get null<br/>
2012-07-11T09:27:02 <hardy_> in which case you have to go the the annotation and get the default value<br/>
2012-07-11T09:27:29 <emmanuel> ok<br/>
2012-07-11T09:27:35 <hardy_> <a href="https://github.com/hibernate/hibernate-orm/blob/metamodel/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java#L91">https://github.com/hibernate/hibernate-orm/blob/metamodel/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java#L91</a><br/>
2012-07-11T09:27:50 <hardy_> that's what the helper tries to hide from you<br/>
2012-07-11T09:28:03 <emmanuel> I've seen your code but Iwasn't expecting jandex to return a ann value null<br/>
2012-07-11T09:28:12 <emmanuel> when you expect a primitive int<br/>
2012-07-11T09:28:16 <emmanuel> but that makes sense<br/>
2012-07-11T09:28:22 <emmanuel> in a twisted way<br/>
2012-07-11T09:28:29 <emmanuel> Ah another question<br/>
2012-07-11T09:28:30 <hardy_> in a twisted way indeed<br/>
2012-07-11T09:28:38 <emmanuel> you get the Type<br/>
2012-07-11T09:28:43 <emmanuel> but no info about generics right?<br/>
2012-07-11T09:29:01 <emmanuel> so for generics you guys go back th Java's reflection<br/>
2012-07-11T09:29:06 <hardy_> getting back to annotations commons I guess<br/>
2012-07-11T09:29:11 <hardy_> yes<br/>
2012-07-11T09:29:13 <emmanuel> ok<br/>
2012-07-11T09:29:39 <emmanuel> So you've changed the code to be visitor based<br/>
2012-07-11T09:29:42 <hardy_> there are libraries which do the reflection bit<br/>
2012-07-11T09:29:49 <emmanuel> or do you still walk imperatively through the structure<br/>
2012-07-11T09:30:11 <emmanuel> Say you do getAnnotations(Entity.class) ~<br/>
2012-07-11T09:30:19 <emmanuel> but form there you walk heach property<br/>
2012-07-11T09:30:24 <hardy_> right<br/>
2012-07-11T09:30:25 <emmanuel> imperatively right?<br/>
2012-07-11T09:30:26 <emmanuel> ok cool<br/>
2012-07-11T09:30:33 <emmanuel> Thanks for all that info<br/>
2012-07-11T09:30:36 <hardy_> np<br/>
2012-07-11T09:30:43 <emmanuel> I'll record it in <a href="https://hibernate.onjira.com/browse/OGM-208" title="Create facility for OGM core and Dialects to receive custom metadata (annotation, programmatic) associated to entities, properties or associations">OGM-208</a> for posterity<br/>
2012-07-11T09:30:44 <jbossbot> jira <a href="https://hibernate.onjira.com/browse/OGM-208" title="Create facility for OGM core and Dialects to receive custom metadata (annotation, programmatic) associated to entities, properties or associations">OGM-208</a> Create facility for OGM core and Dialects to receive custom metadata (annotation, programmatic) associated to entities, properties or associations <span class="error">[Open (Unresolved) Bug, Critical, Unassigned]</span> <a href="https://hibernate.onjira.com/browse/OGM-208">https://hibernate.onjira.com/browse/OGM-208</a><br/>
2012-07-11T09:31:01 <emmanuel> Jandex is bitter sweet to me<br/>
2012-07-11T09:31:12 <emmanuel> the untype-safety is really hurting my feelings <img class="emoticon" src="https://hibernate.onjira.com/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/><br/>
2012-07-11T09:31:15 <hardy_> lol<br/>
2012-07-11T09:31:26 <hardy_> it is not too bad<br/>
2012-07-11T09:32:34 <hardy_> but I agree it is a little bitter sweet. imo the sweetness is definitely winning though</p></div>
<div style="color:#505050;padding:4px 0 0 0;"> </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td><!-- End #email-page -->
</tr>
<tr valign="top">
<td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:10px;line-height:14px;padding: 0 16px 16px 16px;text-align:center;">
This message is automatically generated by JIRA.<br />
If you think it was sent incorrectly, please contact your <a style='color:#6c797f;' href='https://hibernate.onjira.com/secure/ContactAdministrators!default.jspa'>JIRA administrators</a>.<br />
For more information on JIRA, see: <a style='color:#6c797f;' href='http://www.atlassian.com/software/jira'>http://www.atlassian.com/software/jira</a>
</td>
</tr>
</table><!-- End #email-wrap -->
</div><!-- End #email-body -->