Brian Mulholland

Ranch Hand
+ Follow
since Mar 12, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brian Mulholland

Hi Tim,

Yes, but spring-ldap supports BOTH a jdbc transaction and an ldap connection that it simulates transactional control over by using an offsetting transaction when you want to rollback.  Thus it simulates an XA transactional environment even though LDAP doesn't support it.

But because our regular jdbc transactions all need this audit logging code, we want this one to have it too.  It's just proving harder to get my claws into the spring workings so that I can make it work like the jdbc one works.

If you know anything, even just a lead it might get me closer?
4 years ago
We have a custom transaction manager in use in most of our apps that does a bit of work in the doBegin but otherwise just defers everything to it's superclass (the spring class).  This little bit of work is necessary for an audit logging requirement.

However, we have one app that uses spring-ldap, and that transaction manager has no attribute that allows us to specify an alternate class.  So I am looking for how to get my hooks in to run my bit of code before every transaction.  The transaction manager class seems to be determined internal to sping-ldap when we make this declaration:



If there's a way other than subclassing, like registering a listener somewhere that can give us access to the jdbc connection early enough in the transaction, we can use that.  Of if someone knows how to make spring-ldap use a custom subclass, that would work.
4 years ago
We have a legacy Spring 3.2 app.  It has a hibernate session factory with a particular set of hibernate properties that work for our j2ee deployment.  But for our test case, i want everything else in that file to be the same, but I need to set two additional properties.  How can I modify it from my console test?

  <property name="hibernateProperties">
    <props>
 <prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
         <prop key="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</prop>
       <prop key="hibernate.bytecode.provider">javassist</prop>
       <prop key="hibernate.show_sql">${show_sql}</prop>
       <prop key="hibernate.cache.use_second_level_cache">${show_L2_cache}</prop>
       <prop key="hibernate.default_schema">${schema}</prop>
       <prop key="javax.persistence.validation.mode">none</prop>
       <prop key="testOnBorrow">false</prop>

    </props>
  </property>

I need to add those bottom two.  They don't normally exist in that file.  The below is how I am starting up, and it works, but not without those two params set.  But I only want them in the console run, not in the real file.  Is there a way I can add them just for test?

DriverManagerDataSource ds = new DriverManagerDataSource(dbUrl, dbUser, dbPass);
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
builder.bind(dbJndi, ds);
builder.activate();
       springCtx = new ClassPathXmlApplicationContext("WEB-INF/app-config.xml");

5 years ago
SOLVED - So, I was doing it right. The log4j.configurationFile DOES allow log4j2.server.xml just as I wanted. But we had a lingering log4jConfigListener defined in our web.xml that I didn't know about (darn co-workers, always doin' stuff). For some reason, when this was there, that config DEMANDED an absolute URL. When I removed it, everything worked....smooth as butter.
Tim,

The log4j docs themselves recommend putting the config files in your classpath root. I am doing exactly that, just like you say you are. But I merely want to have two there, and control which one is used by the environment setting log4j makes available. Log4j 1.2 makes this possible because I can give a simple file name to replace the default. Log4j 2's preference for absolute paths makes it brittle. I run multiple apps in the same jvm on our server, so absolute paths absolutely doesn't work. I can't specify /opt/long path to my webapp/WEB-INF/classes/log4j.server.xml because that long path would include the SPECIFIC application. Thus the config would not affect the other applications. See the dilemma?
In Log4j 1.2, I used log4j.configuration to specify a log4j.server.properties. then, in the root of my classpath both a log4j.properties and a log4j.server.properties were there. Thus, in localhost, with no system property set, the former would direct logging output to the console of the IDEas specified in log4j.properties. But on the server, the log4j.configuration=log4j.server.properties would be set, and output would go to the various files in the logging folders like we want on the servers in our various environments, as defined in log4j.server.properties.

I want to do the same thing on log4j 2. But the log4j.configurationFile appears to demand an absolute URL. But the absolute file path will be different for each webapp installed on that server. I just want to specify log4j2.server.xml to get the same effect I got under log4j 1.2. When I try, I get "Unable to access log4j2.server.xml java.lang.IllegalArgumentException: URI is not absolute".

How can I get the same effect I got under 1.2, without having some script replace the file?
I am SOOO close to having what I want work. The plan is to move 99% of our properties to database. But we want the datasource's jndi setting to remain in a local properties file as it has always been. Everything works if I hardcode the ds name in the app.xml, but when I specify ${ds.jndi} to point to our property file, it fails. Here's what I got:



The error basically just says "WTF is ${ds.jndi}?" It's trying to resolve that literally as a jndi name. Clearly, the creation of the databaseConfigurator is happening BEFORE the propertyConfigurer pointed at the local property file can do it's job. I tried setting order, and many other permutations, and none work. I have apps using spring 4 and spring 3.2, so ideally a solution that works in both is preferred, but if I had to, I could live with hard-coding in 3.2 until we get permission to upgrade those apps. Any ideas?
7 years ago
I have a query with a bunch of joined tables, and have traditionally used the aliasToBean result transformer for such purposes. However, requirements recently had me stick a CLOB into this bean. I am mapping it to a String (though i also tried Object and that didn't work either). The error is:

Exception:


I saw a post online (http://javatechtricks.blogspot.com/2012/12/hibernate-clob-to-string-conversion.html) about someone saying that Hibernate's result transformer chose not to work with CLOBs due to potential memory issue. But most of the time, my field really isn't going to be that large. Several Kb will be as large as it gets. He specced out a resulttransformer of his own to convert the clobs...but it doesn't work. It gives the error " com.ibm.db2.jcc.a.SqlException: [jcc][10120][11936][4.3.111] Invalid operation: Lob is closed. ERRORCODE=-4470, SQLSTATE=null" everytime i invoke getAsciiStream().

It appears that Hibernate already closed the result set or something at that point. How can I process CLOBs in my joined query that produces a hybrid bean not an entity mapped straight to the table.
I hope this is the right group to post this in. None of them seemed perfect to me.

Anyway, here's what I know. We have many j2ee apps running hibernate 3. A previous developer discovered that websphere loaded a copy of jpa in it's startup, and that he was getting version clashes as a result. So he slipped the jpa 2.0 jar into the jre/lib/ext folder to get it loaded first. Problem solved, he thought.

But now we're starting to convert some of our apps to Hibernate 4, which needs jpa 2.1 jar. I don't want to repeat the same trick. For one, it seems like the wrong solution. But also, will it be backwards compatible? Will we always be demendent on this trick even if this one was backwards compatible?

What is the "right way" to do this? The solution my colleague found, while it works, seems like a hack. There must be a beter way so that each app can run it's own jpa jar dependency. Sticking it in web-inf/lib and so forth doesn't work because the Webspere classloader loads the wrong version far earlier.

(update)
Forgot to post the stack trace.
Caused by: java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3762)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:339)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:427)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 95 more
So I recently rediscovered this post and thought I'd post the solution for posterity. When exporting the jars in RAD, the jar wizard has a checkbox called "Add Directory Entries" on the first page of the wizard. Check that. Without it, my packagesToScan reference, which was to a root of the package with the entities in it (since there is more than one package of entities), would not be found. It acted like there were no entitites. Checking this adds stuff to the manifest and causes the classes to be found by the annotation scanner.
We have a new webapp that we are prepping for deployment. We changed how we include our jars, from just manually dumping them into the web-inf/lib to using eclipse's deployment assembly to move them from a common location into the web-inf/lib dynamically, creating one repository for our libs. This tactic works fine with everything but one jar...the one our hibernate entities are in.

The jar is there, we can see it. It's in the classpath, we can instantiate it. But when we run, we get an exception for unknown entity as if the annotations from the target entity were never run. When we replace our "packagesToScan" declaration with a "annotatedClasses" list, it works fine. Yet our packagesToScan looks right. I'd much rather use the flexible packagesToScan than has developers required to do the easy-to-forget step of declaring their classes each time.

Anyone have any idea why this might be?

spring config (the below shows all three at the same time, in reality we comment one in at a time):



Exception:

We have a web service we just deployed. It's processing requests and no errors come from it's log. However, the app that is it's primary consumer is logging exceptions. ALOT of them. See trace below.

Note that the web service request appears to SUCCEED. But the exception gets logged out anyway, and is causing our logs to roll like crazy.

We are on WAS 7.0.0.5. This does not happen in our local environment.

Web Service Client Code:


Exception:
10 years ago
I gather that TransactionAwareDataSourceProxy seems to be intended for this use, but I see no examples. I just see people saying that this (integrating legacy JDBC and JTA) is what it is for.

It feels like I should somehow start the JTA transaction outside the method and not use the annotation. If the connection is in the session, bound to the thread and transactions started, then everything should pick up automagically right? But if so, I am not sure how to do that.
We have a web service we are implementing that is going to have to participate in global transactions with the client. For our Hibernate/Spring apps where we use @Transactional, this is not a problem. However, we have at least two legacy applications using bare bones JDBC. They are large enough that retrofitting is not viable in the near term, yet they must talk to this web service and participate in the two-phase commit.

We were hoping we could distribute a jar with the web service client in it that would expose a method that would take the JDBC connection, hook it into an @Transactional boundary, do some work, including calling the web service, and be able to have it use the connection provided from the legacy app. In other words, we need a way to hand a particular connection, upon which a transaction has already started, to the @Transactional instead of the one it would naturally allocate. And obviously it could not commit when it leaves since the legacy app does the commiting.

Does anyone have the faintest idea of how to pull this off?
Even if people don't necessarily know the answer, if you know enough to tell me that I am hitting the right switches or not? Am I close? Is there some major piece I didn't talk about or overlooked? I am using an XA data source. Db2 9.5.
10 years ago