I have two databases. One from Oracle 10g. Another from Mysql. I have configured my web application with Nhibernate for Oracle and now I am in need of using the MySQL database. So how can i configure the hibernate.cfg.xml so that i can use both of the database at the same application?
My current hibernate.cfg.xml is:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Data Source=xe;Persist Security Info=True;User ID=hr;Password=hr;Unicode=True</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<!-- mapping files -->
<mapping assembly="DataTransfer" />
</session-factory>
</hibernate-configuration>
You can check "Burrow" addin for nhibernate
http://nhforge.org/wikis/burrow/introduction.aspx
Multiple databases support. multiple databases becomes easy, you don't need a SessionFactoryPath, you simply give Burrow an entity type, and Burrow will find the right ISession for you. If you are using GenericDAO, the multiple DB support can be very transparent - your code does not need to know there are multiple databases.
Seems that you could also use unhaddins, haven't used it and I didn't find the documentation.
http://code.google.com/p/unhaddins/
I had to do that many time ago I followed this article, it's a more complex solution but I paste it just in case.
http://www.codeproject.com/KB/aspnet/NHibernateMultipleDBs.aspx
Here may be a simpler solution. It provides a new feature that allows the hibernate-configuration to have multiple session-factory elements by giving them names, and extends the NHibernate.Cfg.Configuration.Configure to accept a sessionFactoryName.
Configure NHibernate hibernate.cfg.xml file to have more connection strings
Related
The code for vision api works fine when using a java application however when using spring a java.lang.VerifyError exception is thrown on the following line.
Labels app = new Labels(label.getVisionService());
It was certain that i had specified the json credentials for the system and not the web app so i have included the following bean in my root-context.xml:-
<bean id="googleVisionApiAuthenticator" class="com.something.mypackage.Labels">
<property name="APPLICATION_NAME" value="myCompany-VisionLabelSample/1.0" />
<property name="MAX_LABELS" value="3" />
</bean>
After inclusion of these lines in the root-context its gives page not found.
Well the problem was that some of the jars present were duplicate hence the error. A detailed study of the dependencies and removing the extra jars helped solve the error.
Is there a full documentaion of the deployment descriptor that describes each element and each sub-element?
I realy can't find it.
P.S. I ask because I found the way to set maxAge of session cookies by adding
<session-config>
<session-timeout>525600</session-timeout>
<cookie-config>
<max-age>31536000</max-age>
</cookie-config>
</session-config>
into DD. But I cannot find any official documentation that describes <cookie-config> element.
For the standard Java EE deployment descriptor elements, that follows the servlet 3.0 specification, you can address, for instance, Oracle's Weblogic 12c web.xml docs.
Furthermore, for the missing sub-elements that aren't contemplated in the documentation mentioned above, I'd suggest you to give a look to the web-common_3_0.xsd file, which is the common XML Schema for the Servlet 3.0 deployment descriptor (...) in turn used by web.xml and web-fragment.xml web application's war file.
Event though it will force you to read XML, in this file you may check all the elements, as well as their sub-elements, that can be used in web.xml deployment descriptor as, for instance, the cookie-config:
<xsd:element name="cookie-config"
type="javaee:cookie-configType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
The cookie-config element defines the configuration of the
session tracking cookies created by this web application.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
I want to set the Entity Framework ObjectContext in a repository class - the ObjectContext being a property of the repository.
I am using Unity XML configuration:
<register type="IUsersRepository" mapTo="SqlUsersRepository" >
<property name="MyObjectContext">
<value value="Per-Request" typeConverter="ObjectContextTypeConverter" />
</property>
</register>
The ObjectContextTypeConverter interprets the value of the property - in this case "Per-Request" - and uses an ObjectContext stored in HttpContext.Current.Items (a per request collection in asp.net).
The ObjectContextTypeConverter.ConvertFrom method is only called once when the Unity configurations is loaded in the Application_Start method of the Global.asax file. Yet when I try to resolve an interface using Unity - the ConvertFrom method won't be called again.
Is there a way to solve this problem?
The reason is that you're setting it as a value. You can set it as a dependency:
<property name="MyObjectContext">
<dependency />
</property>
and inject the context through an in injection factory:
Container.RegisterType<ObjectContext>(
new InjectionFactory(c => GetTheContextInstance()));
I'm trying to use Jrebel with IntelliJ 10. I'm working on Spring Roo generated project which uses tiles. There are multiple views.xml in my class path.
What I would like to know is if JRebel will pick up changes to views.xml. So far I can't seem to make it.
Just report it to JRebel forum - it will be registered as a feature request
If you are using spring roo generated project than it uses tiles 2.2.1 at least. in that case you dont need Jrebel to do it as Tiles can do it directly, just set the useMutableTilesContainer and checkRefresh properties to true on spring's TilesConfigurer bean
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
id="tilesConfigurer" >
<property name="useMutableTilesContainer">true</property>
<property name="checkRefresh">true</property>
it's explained in detail here: http://lalyos.github.com/blog/2012/08/29/tiles-reload-definitions-in-springmvc/
I need to switch among 3 different environments when developing my web app - Development, UAT, and Prod. I have different database connections in my configuration files for all 3. I have seen switching these settings done manually by changing all references and then rebuilding the solution, and also done with preprocessor directives. Is there an easy way to do this based on some variable so that the configuration doesn't have to be revised when deploying to a new environment every time?
To me it seems that you can benefit from the Visual Studio 2005 Web Deployment Projects.
With that, you can tell it to update/modify sections of your web.config file depending on the build configuration.
Take a look at this blog entry from Scott Gu for a quick overview/sample.
I'm a big fan of using MSBuild, in particular the MSBuild Community Tasks (http://msbuildtasks.tigris.org/) and there is an XSLT task to transform the web.config with the appropriate connection string settings, etc.
I keep these tasks handy:
<Target Name="Configs">
<Xslt RootTag="" Inputs="web.config" Output="Web.$(COMPUTERNAME).config" Xsl="web.config.$(COMPUTERNAME).xslt" Condition="Exists('web.config.$(COMPUTERNAME).xslt')" />
Obviously this isn't 100% what you're after, it's so each dev can have their own web.config.
But there's no reason you couldn't use the above principle to have multiple build configurations which applies the right XSLT.
My XSLT looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!-- Dev -->
<xsl:template match="/configuration/connectionStrings/add[#name='MyConnectionString']/#connectionString">
<xsl:attribute name="connectionString">Data Source=MyServer;Initial Catalog=MyBD;User ID=user;password=pwd</xsl:attribute>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
You can always use NAnt + NAnt.Contrib to modify the web.config during the build.
NAnt has xmlpeek and xmlpoke tasks which allow you to update xml files.
e.g.
<xmlpoke file="${dist.dir}/Web.config"
xpath="/configuration/applicationSettings/MyProj.Web.Properties.Settings/setting[#name = 'MyProj_Web_Service']/value"
value="http://${AppServer}/Service.asmx" />
Scott Hanselman has suggested one way to do this:
http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx
I have adopted the Jean Paul Boodhoo Method of changing configurations.
The general idea is to have one or more TOKENIZED configuration TEMPLATE files instead of the configuration files themselves. Then you have a build script task that replaces the tokens with values from a SINGLE local properties file. This properties file contains all differences in configuration and is unique per working copy.
This system has worked great for me and once initially setup is a breeze to manage environment changes.