I'm taking the ownership of a Java application which works with JBoss, and I found that the Persistence.xml file have the following statments..
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="#USER#"/>
<property name="hibernate.connection.password" value="#PASSWORD#"/>..
USER and PASSWORD are declared in properties file, however the values bounded with At signs is not familiar for me. I've not seen this before, what kind of method is being used here?
If I am not mistaken this is the maven genapp plugin...
The filter itself is used copying the files defined by maven.genapp.repackage and maven.genapp.filter and will replace any occurrence of #PARAM# in the files with the value of maven.genapp.template..
At least that's where I've seen this kind of constructs before.
Related
I am new to hibernate, and I have been tasked with changing the ConnectionProvider from the hibernate default CP to either Hikari (preferred) or C3P0 in a legacy Java application that does not use maven as a repository. The database is PostgreSQL. The hibernate version is hibernate-release-5.2.10.Final. I have added hibernate-hikaricp-5.2.10.Final.jar to the classpath.
I have a pre-existing xml configuration file for hibernate. This has been working for several years, but the project wants to change to a "production ready connection pool". I have added/modified properties for the connection provider as follows:
<property name="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property>
<property name="hibernate.hikari.minimumIdle">5</property>
<property name="hibernate.hikari.maximumPoolSize">20</property>
<property name="hibernate.hikari.idleTimeout">30000</property>
I am getting the following StrategySelectionException (long stack trace reduced to exceptions/causes ... more information available if necessary).
Exception in thread "DatabaseCache initialize thread" org.hibernate.service.spi.ServiceException: Unable to
create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
...
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.hikaricp.internal.HikariCPConnectionProvider] as strategy [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
I made one other change, after first seeing the exception. I added the following property, but it made no difference.
<property name="hibernate.implicit_naming_strategy">default</property>
The full configuration, with some information provided as variables replaced during build, is:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.implicit_naming_strategy">default</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property>
<property name="hibernate.hikari.minimumIdle">5</property>
<property name="hibernate.hikari.maximumPoolSize">20</property>
<property name="hibernate.hikari.idleTimeout">30000</property>
<property name="hibernate.connection.username">${db_user_name}</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">${db_connection_url}</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.jdbc.time_zone">GMT</property>
<property name="hibernate.generate_statistics">false</property> <!-- This affects performance, use only in development -->
<property name="show_sql">false</property>
</session-factory>
</hibernate-configuration>
Any strategies :D to address this would be welcome. Thanks.
Im developing a Jee webapp using JPA/Hibernate as ORM framework, PostgreSQL as db, and Tomcat as server.
When i start the app i want entitymanager to inject some data in my db.
I do that whith
<property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql"/>
in persistence.xml
Everything works fine except that i get some bad encoding like "Ardèche" instead of "Ardèche".
My whole project is in utf-8, my database too.
I had encoding output problems in Intelli-j terminal with tomcat, that i managed to resolve using -Dfile.encoding=UTF-8 in Help | Edit Custom VM Options.
But my data in my db is still wrong, even if in Intelli-J output i get the good result.
If i execute the script straight into pgadmin there is no problem.
I tried everything i could find to solve that, but nothing worked.
I probably have conflict in the configuration now, cause i tried too many different stuff.
My persistence.xml
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/DB" />
<property name="javax.persistence.jdbc.user" value="db" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.charSet" value="UTF-8"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
<property name="hibernate.connection.autocommit" value="true" />
</properties>
It's my first message on stackoverflow so i hope i did everything properly !
Thanks !
thanks for your answer, i just managed to fix it by adding <property name="hibernate.hbm2ddl.charset_name" value="UTF-8"/> to persistence.xml. I didn't check enough the hibernate doc !
I have tried to save the Orbeon forms in Postgres DB. I created data bases persistence layer but still forms are stored in the default eXist DB. I have created context(Data Base source) in the "Server.xml" from the tomcat7 and I have created "properties-local.xml" file in the Orbeon4.8 (orbeon/src/resources/config/properties-local.xml). My reference is this.
Some one help me how to save the orbeon forms in Postgres DB?
Once the database resource is configured, you can tell Orbeon to use it by adding a like like this to your properties-local.xml:
<property as="xs:string" name="oxf.fr.persistence.provider.*.*.*" value="postgresql"/>
You can see the default configuration for the resource names Orbeon accepts out of the box in properties-form-runner.xml.
Exist will still be used for the example forms. But you can disable it with:
<property as="xs:boolean" name="oxf.fr.persistence.exist.active" value="false"/>
If you need to define a resource with a name other than the default names (e.g. postgresql), you will need to provide more information as shown below (remember to replace all occurances of pg_other_name with your resource name).
<property as="xs:string" name="oxf.fr.persistence.provider.*.*.*" value="pg_other_name"/>
<property as="xs:anyURI" name="oxf.fr.persistence.pg_other_name.uri" value="/fr/service/postgresql"/>
<property as="xs:string" name="oxf.fr.persistence.pg_other_name.datasource" value="pg_other_name"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.create-flat-view" value="true"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.autosave" value="true"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.permissions" value="true"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.versioning" value="true"/>
I'm not sure what you mean by "created context in the Server.xml".
In tomcat's server.xml you should have a datasource defined. For example:
<GlobalNamingResources>
<Resource
name="jdbc/postgresql"
auth="Container"
type="javax.sql.DataSource"
initialSize="3"
maxActive="10"
maxIdle="20"
maxWait="30000"
driverClassName="org.postgresql.Driver"
validationQuery="select 1"
testOnBorrow="true"
poolPreparedStatements="true"
username="orbeon"
password="orbeon"
url="jdbc:postgresql://server:5432/database?useUnicode=true&characterEncoding=UTF8&socketTimeout=30&tcpKeepAlive=true"/>
</GlobalNamingResources>
Then in tomcat's context.xml you should have a ResourceLink for the datasource:
<ResourceLink global="jdbc/postgresql" name="jdbc/postgresql" type="javax.sql.DataSource"/>
properties-local.xml should be either in webapps/orbeon/WEB-INF/resources/config or in an external directory you have defined in tomcat's context.xml, for example:
<Parameter name="oxf.resources.priority.0" override="false" value="org.orbeon.oxf.resources.FilesystemResourceManagerFactory"/>
<Parameter name="oxf.resources.priority.0.oxf.resources.filesystem.sandbox-directory" override="false" value="C:/orbeon_resources"/>
In that case the properties-local.xml should be here: C:\orbeon_resources\properties-local.xml. See Storing configurations outside of the Orbeon Forms war file.
Also, make sure you have performed the Orbeon Forms setup. That is general database configuration, not specific to postgresql or any other database implementation. The examples they give are for oracle but you can just replace oracle with postgresql.
I am using Eclipse BIRT Designer Version 4.3.2.v20140211-1400 Build 4.3.2.v20140211-1526 against Sybase ASE. I want the user prompt for two date parameters to format as 7-30-14. Currently the default is showing 2014-7-30.
Per recommendations from other postings I chose Properties for the Parameter from the Eclipse Outline view. In the Edit Properties under Display As it shows the Custom Format I selected M/d/yy and the Preview shows 7/30/14. However, when I run the report it still requires me to enter it as yyyy-mm-dd and errors out with a bad date any other way.
Am I missing something else?
Here is the xml for the parameters
<parameters>
<scalar-parameter name="report_dt" id="85">
<text-property name="promptText">Enter Date as MM/dd/yy</text-property>
<property name="valueType">static</property>
<property name="isRequired">true</property>
<property name="dataType">date</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="javascript">params["end_dt"].value</value>
</simple-property-list>
<list-property name="selectionList"/>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Custom</property>
<property name="pattern">M/d/yy</property>
</structure>
</scalar-parameter>
<scalar-parameter name="end_dt" id="88">
<text-property name="promptText">Enter the end of the range. By default this will be the same as the start date</text-property>
<property name="valueType">static</property>
<property name="isRequired">true</property>
<property name="dataType">date</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="javascript">params["report_dt"].value</value>
</simple-property-list>
<list-property name="selectionList"/>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Custom</property>
<property name="pattern">M/d/yy</property>
</structure>
</scalar-parameter>
</parameters>
I am working on a Spring WebFlow project which has a lot of property values in XML files, as any Spring programmer knows. I have database user names, password, URLs, etc.
We are using Eclipse with Spring WebFlow and Maven. We are trying to have an SA do the builds but the SA does not want to go into the XML files to change the values, but on the other hand, we don't know the production values. How do we work with this?
Most SA are more willing and confident to deal with .properties file rather than .xml.
Spring provide PropertyPlaceholderConfigurer to let you define everything into one or several .properties file and substitute the placeholder in applicationContext.xml.
Create a app.properties under src/main/resources/ folder:
... ...
# Dadabase connection settings:
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/app_db
jdbc.username=app_admin
jdbc.password=password
... ...
And use PropertyPlaceholderConfigurer in applicationContext.xml like so:
... ...
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>app.properties</value>
</property>
</bean>
... ...
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
Check out Spring PropertyPlaceholderConfigurer Example for more details.
In addition, from application deployment perspective, we usually package app in some executable format and the .properties files are usually packed inside the executable war or ear file. A simple solution is to configure your PropertyPlaceholderConfigurer bean to resolve properties from multiple location in a pre-defined order, so in the deployment environment, you can use a fixed location or environment variable to specify the properties file, also note that in order to simplify the deploy/configure task for SA, we usually use a single external .properties file define all runtime configuration, like so:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- Default location inside war file -->
<value>classpath:app.properties</value>
<!-- Environment specific location, a fixed path on server -->
<value>file:///opt/my-app/conf/app.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
Hope this helps.
Another simple way is Spring Expression Language (SpEL)
for example
<property name="url" value="#{ systemProperties['jdbc.url'] }" />
Documentation
spring documentations
Also you can define a propertyConfigurer programmatically in configuration class:
#Configuration
#PropertySource("classpath:application.properties")
public class PropertiesConfiguration {
#Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(Environment env) {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setEnvironment(env);
return configurer;
}
}