How to ignore creating tables if existing in Postgresql database with eclipselink? - postgresql

I'm using a Postgresql database with eclipselink2.3 provider in JOnAS (Java environment). My configuration is :
persistence.xml:
...
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.target-database" value="POSTGRESQL"/>
...
Postgresql version is
VersionĀ : 8.4.11-0squeeze1
JDBC driver version is
postgresql-8.4-703.jdbc3.jar
When database is empty, there is no problem.
My problem is when eclipselink.ddl-generation is set to create-tables and tables are already existing in data base, an error is occured and process doesn't not continue with the next statement as explained here.
Does anyone see a solution for that?

I don't see any property that would prevent throwin error in your case. So i would suggest the following. You should have 3 persistence.xml files for 3 different environoments: development, testing and production.
In development environoment you want to work with clean database, so
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
The same with testing environoment, but in this case I would use DBUnit to fill database with test data.
In production you don't want to mess with database structure so
<property name="eclipselink.ddl-generation" value="none"/>
is the right choice.
If you use ant or maven such configuration is fairly easy to accomplish (you might find examples in the net, since this is pretty standard approach).
I guess you will not like this answer ;), since this looks like quite a lot of additional work, but in the long run clean configuration and separation would pay off.

The "create-tables" option does not fail if the table already exists. It will log the error, but continue.
If you don't want to see the error, you can turn off logging.
What error do you get?

Related

why is my eclipse RCP product locked and can't be updated?

I am building an Eclipse RCP-based product, and I am running into an issue where when I try to use the built-in p2 UI to install updates to the product, I get an error message in the dialog that "Insufficient access privileges to apply this update."
I have debugged into Eclipse and found that the 'root cause' is that there is a p2 .profile file that has xml that includes this snippet:
<iuProperties id='com.datical.db.ui.product' version='1.33.0.201412032223'>
<properties size='4'>
<property name='org.eclipse.equinox.p2.internal.inclusion.rules' value='STRICT'/>
<property name='org.eclipse.equinox.p2.type.root' value='true'/>
<property name='org.eclipse.equinox.p2.type.lock' value='3'/>
<property name='org.eclipse.equinox.p2.base' value='true'/>
</properties>
</iuProperties>
The relevant line is the one that says <property name='org.eclipse.equinox.p2.type.lock' value='3'/>
I'm not sure what I am doing wrong - I think I must have something awry in my product definition or my feature definition or in my install process that is causing this line to be there.
When I step through the Eclipse code (our target environment is 3.7/Indigo) I see that the profile is being written inside org.eclipse.equinox.internal.p2.engine:SurrogateProfileHandler:addSharedProfileBaseIUs (which is private static.) That is called from SurrogateProfileHandler:createProfile
The product's p2 repository is being built using the tycho plugins, version 0.15.
We finally discovered another piece of information that may be relevant. We were using a custom OSGI directory name. When we removed that, everything started working as expected.
It seems that you have a shared install where the product you would like to update is (potentially) used by many installations as a base - and therefore cannot be updated.
This kind of problem goes beyond what can be answered well on stackoverflow because you'd really need to provide an example project and exact steps to reproduce the problem.
The most plausible cause for the symptoms you are seeing is some kind of file system permission problem. This documentation mentions that you need write permission to the installation directory for running Eclipse with -initialize. Maybe you are lacking some permissions making some of the -initialize procedure fail and leave the installation in an inconsistent state.

JRebel: how to disable hbm2dll schema export in JRebel?

The question says it all. i'm using jrebel (5.5)
for hibernate plugin it says: "Enables automatic schema updating if hibernate.hbm2ddl.auto=update or schemaUpdate=true on org.springframework.orm.hibernate3.LocalSessionFactoryBean."
how can i disable it (or change)? it deletes and recreates (incorrect) my database schema on every start/stop and clean...
thx
Pardon,
i've found out that my full text search failed badly.
there was another setting for this in the persistence.xml. feeling dumb right now.
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
change it to:
<property name="hibernate.hbm2ddl.auto" value="none" />
did it for me

Problems with GWT app when deploying in Apache Tomcat 7

I'm using
GWT Framework
GXT 4.2
MySQL
Gilead
c3p0
Hibernate
When I run my application from eclipse works perfectly each remote procedures, then generated the compiler war with google and I'm success all 6 reviews finally copy the generated war (which is a folder and not a. War) in webapps apache-tomcat 7 and deploy my application apparently works but fails in the following:
Does not perform well validations logic to insert data into the database, sometimes it works and sometimes not.
When I make a data operation such as recovering "registered assists a teacher" sometimes the data recovering well and sometimes not (it should be noted that the tuples retrieved before passing through a logic that puts them a state "delay" by according to the time recorded example), it seems that failure is part of the java code, but when I run it from eclipse works perfectly the same example.
Every so long (8 hours average) to open the web page with the server path I get "Connection error with bd" or "error retrieving fields to the combo box" (I do this before showing)
If you could help me I'll be a thousand grateful, I think the google compiler does not compile the code in java good or not can be wrong.
Part of my hibernate.cfg files is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration
DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-
3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:mysql://domain/bd</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.current_session_context_class">thread</property>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property
name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvide
1
5
20
300
0
100
SELECT 1;
I think it is the default 8h connection reset of mysql and hibernate.
It is impossible, that the hibernate (pure java, not gwt compiled to JS) can influence the database connection.
But your hibernate configuration seems to be correct.

Could not create the driver from NHibernate.Driver.NpgsqlDriver

I've inherited a C#/NHibernate/MS SQL Server project and am new to NHibernate. One of the first tasks given to me was to migrate the database from MS SQL Server (2008 R2) to Postgresql 9.2. I'm using the Npgsql 2.0.12 (.net 2.0 version). The Mono.Security.dll and Npgsql.dll are included in my project References and they exist in my bin directory. When the code executes the following line:
SessionFactory.OpenSession();
an exception is thrown with the message
"Could not create the driver from NHibernate.Driver.NpgsqlDriver."
Searching the web, gave me a few ideas but none have worked. This code I've inherited is in production at several clients with no issues using MS SQL Server. Here is my hibernate.cfg.xml file:
<?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="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="connection.connection_string">server=localhost;Port=5432;Database=vehicletracker;User Id=postgres;Password=********;</property>
</session-factory>
</hibernate-configuration>
I did not forget to include "using Npgsql;", it is there. Any suggestions?
Regards,
B
I found the answer to my own question. There were several issues specific to my work environment but ultimately the Mono.Security.dll and Npgsql.dll were not available in my final output directory. The two files were present in the bin directory of my Data Access Layer (a class library) but not in the bin directory of my Test Project that called the class library. Everything is working fine now.
If you're using NuGet for the nhibernate libraries try uninstalling the packages and reinstall them. I'm sure there is a more efficient way someone knows of to fix this kind of issue but for me it solved this exact issue.

Is there Any Way to Enforce RuntimeUnenhancedClasses in EE Configuration

I just spent a half hour debugging some new code that's not broken because I forgot to check (again!) my logs for this dreaded message:
WARN openjpa.Enhance - Creating subclass for ...
I'm running OpenJPA 2.1.0 inside an OpenEJB 3.2 snapshot build, Java 1.6.0_25, and Eclipse Helios. My entities are enhanced using the ant PCEnhancerTask.
My META-INF/openjpa.xml contains
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />
Is there anyway with this EE configuration to have OpenJPA enforce the RuntimeUnenhancedClasses option as it does in an SE configuration?
I suspect my 'real' problem stems from an Eclipse svn update that sometimes touches my JPA entity source, causing a build that overwrites my enhanced classes.
It's frustrating how often I run a unit test from the IDE that fails in some weird way, and I go digging through my code looking for a problem when all I need to do is run the enhancer.
Put the <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" /> META-INF/persistence.xml.
Looks like we're logging this action on debug level (maybe it should be info level), but OpenEJB will set that property to the default as it was in OpenJPA 1.x so that apps that worked with OpenEJB 3.1.x/OpenJPA 1.x will still work without modification in 3.2.x. If the property is already set in the persistence.xml it will never be overridden, so setting it there will have the effect you want.
Open to suggestions on how to save others in the same boat some time in the future. Seems either looking in the openjpa.xml file and seeing the property set already or issuing the log message on info would do it -- or both.
It sounds like for whatever reason your properties aren't being picked up when running in the container.
I have a number of possible solutions:
Try setting your properties in META-INF/persistence.xml. I assume you have these properties in the openjpa.xml file for a reason, but it might help us figure out where the real problem is.
Set -Dopenjpa.RuntimeUnenhancedClasses=false as a JVM property. This will apply to all PUs for a given JVM.
Move to a version of OpenJPA that is >= 2.0.0. RuntimeUnenhancedClasses was turned off as the default behavior in that release.