Using Griffon 1.2 and JPA is there any way to configure the persistence.xml with environmental properties - so I can have a different jdbc.url for dev/test/prod ?
i.e. conf/metainf/persistence.xml
<property name="javax.persistence.jdbc.url" value="${javax.persistence.jdbc.url}" />
I was hoping something like this would work in JpaConfig.groovy
environments {
development {
persistenceUnit {
entityManager {
// EntityManager properties go here
javax.persistence.jdbc.url = 'jdbc:h2:mem:sample'
}
}
}...
I could create multiple duplicate persistence xml files and I believe I can specify the active persistence unit in JpaConfig.groovy. Or is there some other way to parameterize the JPA configuration per environment?
Thanks
I'm afraid parameterizable persistence.xml files are not supported at the moment because those files are never touched by the plugin; however this would be a nice addition to the plugin. Would you care to register a ticket at http://jira.codehaus.org/browse/griffon ?
In the meantime, setting all relevant properties in JpaConfig.groovy is the only way to achieve this.
Related
Is it possible for me to have two different persistence.xml files under META-INF eg. persistence-one.xml and persistence-two.xml and then somehow use <property name="persistenceXmlLocation" value="${db.persistence.file.name}"/> in my spring-context.xml to use the appropriate one using property files ?
I am doing this because I have two separate environments with different configurations - providers/dialects etc.
If I do above changes then I get Caused by: java.io.FileNotFoundException: and it's not able to read the appropriate file.
How I can make this work ?
Spring 3, Hibernate 5.3
Whoaa... spring 3 with hibernate 5 is going to be... challenging.
In any case, I'd try using <property name="persistenceProvider" value="org.hibernate.jpa.HibernatePersistenceProvider" /> instead of jpaVendorAdapter.
You might want to take a look at the bean's javadoc to see which other properties might be relevant (alternatively, you can use the persistenceXmlLocation property and load all the properties from either persistence_dev.xml or persistence_prod.xml)
While watching one of my colleagues work in IntelliJ, I was jealous to note that he could Ctrl/Command+Click on the name of a spring bean, context, or resource in either a Java annotation or a Spring context file and IntelliJ would open the backing declaration or file.
I've installed the STS suite of plugins for Eclipse, but this has only given me the ability to open declarations for beans referred to in a spring context file. E.g., command+click only works in my context file for: <bean ... ref="bean-name"/>.
Specifically, things I can't open the declaration/resource for automatically are:
In my context file: <import resource="classpath:config/anotherContext.xml"/>, I cannot open the resource anotherContext.xml. The open resource dialogue helps, but doesn't tell me which one my classpath is actually giving me.
In my Java file: #ContextConfiguration({"classpath:/config/yetAnotherContext.xml"}), I cannot automatically open the resource of yetAnotherContext.xml.
In my Java file: #Resource(name = "another-bean-name"), I cannot open the bean declaration. This one is especially difficult to discover in Eclipse, I haven't figured out an easy way to discover the bean declaration short of full search.
Surely there's a way in Eclipse to automatically discover declarations or resources for spring beans and contexts as they are used in both Java annotations and context files?
I found a solution for my first example, specifically, finding a spring resource imported into a spring context file in this StackOverflow question. Specifically, in the project properties under Spring->Beans Support, select the checkbox for Enable support for <import /> element in configuration files.
This also gives the ability to open bean declarations for beans defined in imported spring resource files.
I have yet to discover similar functionality for Java files that wire in Spring resources and beans via annotations.
I have a java-ee web application that uses a persistence unit that is packaged as a jar dependency (Entity classes, EJB repositories, persistence.xml).
In order to get some acceptance tests running for the web application i need to override a property in the packaged persistence.xml. To be specific i need to disable the by default active eclipselink shared object cache by setting the following property.
<property name="eclipselink.cache.shared.default" value="false"/>
This is necessary because the acceptance tests are directly prepare/cleanup the database with dbunit. These modifications will put the eclipselink cache in a stale state (because the persistence unit is not involved in these modifications).
Is there a way in java-ee (or glassfish specific) to override properties in a persistence.xml that is located in a jar (starting from the web application war file, that is deployed when running my tests)?
There may be other ways, for example building the jar dependency specific for a test deployment, but this route seems complicated to me for only override one property in my persistence.xml.
You can pass a properties map to Persistence.createEntityManagerFactory(). To do this you must manage your persistence context yourself (will not be able to inject it).
Another option is to set the property as a Java system property (-D=), this will not override an existing property in the persistence.xml, but with work if the property is not in the persistence.xml.
Another option is to put a SessionCustomizer or a SessionTuner in your persistence.xml to allow your own code to modify the configuration at runtime.
I've searched for an answer to my problem on google and various forums, but couldn't find a solution. I'm currently trying to modify the persistence.xml at runtime by adding a persistence unit to the file.
The solutions for this question were always "pass a Map of properties when creating an EntityManagerFactory (or EntityManager)" but i need to save the new persistence unit in the persistence.xml, because the application is going to have 100 or even more persistence unit's, one for each tenant that will register to the service, each tenant will have his own database. I'm currently using EclipseLink 2.3.3 as my JPA implementation, EJB 3.1 and jboss 7.1.1.Final as my application server.
Is it possible to modify the persistence.xml at runtime (on the fly)?
The persistence.xml is a deployed artifact, so would be difficult to modify at runtime. I think passing a properties map to createEntityManagerFactory is your best solution, what issue are you having with this?
You may also want to try using the PersistenceProvider API, createContainerEntityManagerFactory() that takes a PersistenceUnitInfo.
Also, consider using EclipseLink's multi-tenant support,
http://www.eclipse.org/eclipselink/documentation/2.5/solutions/multitenancy.htm
I typically use groovy to construct simple bean but the Spring IDE plugin to eclipse fails to build when I try to set a property that is generated by groovy without an explicit setter. For example,
class MyGrooyClass {
def propertyA
}
and in the spring configuration file I have something that looks like:
<bean id="MyGroovyClassBean" class="MyGroovyClass">
<property name="propertyA" value="someValue"/>
</bean>
The spring builder says there is no such property but it is in the bytecode since it is automatically generated by groovy. If I don't validate that bean, everything works, so spring can resolve the property, but it seems to be an issue with the plugin. Is there a way to work around this or to disable validating a particular bean?
EDIT: I can construct the bean using the groovy specific syntax
<lang:groovy id="..." script-source="...">
<lang:property name="propertyA" value="someValue"/>
</lang>
but it seems odd that I should need to do this just for the plugin.
Thanks,
Jeff
It definitely looks like a bug in the Spring IDE plugin. I've also had issues where the content assist does not show auto-complete for properties of a Groovy bean.
I see the same issue in the project I am working on. Consequently I do not use the Spring Validator.
As confirmed by Chris Dail, this is a bug in the Spring IDE plugin. I posted it in the Spring forums http://forum.springsource.org/showthread.php?p=271607&posted=1#post271607 and it has been fixed in the nightly build.