7:00 – 5:30 VTX
- Finished Social Media and Trust during the Gezi Protests in Turkey.
- More Hibernate
- After stepping through the ‘Showroom’ example on pg 54 (Using a Join Table), of Just Hibernate I think I see my problem. In my case, the corpus has already been created and exists as an entry in the corpora table. I need to add a relationship when a word is run against a new corpus. Which come to think about it, should have the word count in it. Maybe?
- Ok, I don’t like the way that ManyToMany is implemented. Hibernate should be smart enough to figure out how to make a default mapping table. Sigh.
- And you have to call each object with the other object or it doesn’t load properly.
- After being annoyed for a while, I decided to try reflection as a making fewer calls. The following still needs the get/set member element calls, but I like the direction it’s going. Will work on it some more tomorrow (need to add the call on the this class):
public void addM2M(Object obj){ System.out.println("person.addM2M"); Class thisClass = this.getClass(); String thisName = thisClass.getName(); Class thatClass = obj.getClass(); Method[] thatMethods = thatClass.getMethods(); Method thatMethod = null; for(int i = 0; i < thatMethods.length; ++i){ Method m = thatMethods[i]; Type[] types = m.getGenericParameterTypes(); if (types.length == 1) { // looking for one arg setters for (int j = 0; j < types.length; ++j) { Type t = types[j]; if ((t.getTypeName() == thisName)) { thatMethod = m; break; } } } if(thatMethod != null){ break; } } if(thatMethod != null){ try { thatMethod.setAccessible(true); thatMethod.invoke(obj, this); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { System.out.println("addM2M failed: "+e.getCause().getMessage()); e.printStackTrace(); } } }
