Hi all: I´m using openJPA 1.2.0 in a standalone application. Here is my persistence.xml
[code] <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <!-- We need to enumerate each persistent class first in the persistence.xml See: http://issues.apache.org/jira/browse/OPENJPA-78 --> <!-- A persistence unit is a set of listed persistent entities as well the configuration of an EntityManagerFactory. We configure each example in a separate persistence-unit. --> <persistence-unit name="XXX" transaction-type="RESOURCE_LOCAL"> <!-- The default provider can be OpenJPA, or some other product. This element is optional if OpenJPA is the only JPA provider in the current classloading environment, but can be specified in cases where there are multiple JPA implementations available. --> <provider> org.apache.openjpa.persistence.PersistenceProviderImpl </provider> <!-- We must enumerate each entity in the persistence unit --> <class>com.tecnalis.casino.blackjack.entity.Game</class> <class>com.tecnalis.casino.blackjack.entity.GameLog</class> <class>com.tecnalis.casino.blackjack.entity.Machine</class> <class>com.tecnalis.casino.blackjack.entity.MachineConfiguration</class> <properties> <!-- We can configure the default OpenJPA properties here. They happen to be commented out here since the provided examples all specify the values via System properties. --> <property name="openjpa.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver, Url=jdbc:mysql://XXX?zeroDateTimeBehavior=convertToNull, MaxActive=100, MaxWait=10000, TestOnBorrow=true, Username=XXX, Password=XXX"/> <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/> <!-- <property name="openjpa.ConnectionURL" value="jdbc:mysql:// 192.168.16.6:3306/BLACKJACK?zeroDateTimeBehavior=convertToNull"/> <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/> <property name="openjpa.ConnectionUserName" value="root"/> <property name="openjpa.ConnectionPassword" value=""/> --> </properties> </persistence-unit> </persistence> [/code] And here is a class which uses domain classes [code] * public* *class* GameHelper { *private* *static* EntityManager *em*; *static* { EntityManagerFactory emf = Persistence.*createEntityManagerFactory*( "blackjack"); *em* = emf.createEntityManager(); } *public* *static* Game getGame(*int* idGame) *throws* Exception { *try* { *return* *em*.find(Game.*class*, idGame); } *catch* (Exception e) { e.printStackTrace(); *throw* e; } } *public* *static* Game saveGame(*int* statusId, *int* playerId, *int*machineId, Date initDate, Date endDate) *throws* Exception { *try* { Game game = *new* Game(); game.setStatusId(statusId); game.setPlayerId(playerId); game.setMachineId(*em*.find(Machine.*class*, machineId)); game.setInitDate(*new* Timestamp(initDate.getTime())); game.setEndDate(*new* Timestamp(endDate.getTime())); *em*.getTransaction().begin(); *em*.persist(game); *em*.getTransaction().commit(); *return* game; } *catch* (Exception e) { e.printStackTrace(); *throw* e; } } *public* *static* *void* saveTrace(*int* gameId, *int* methodId, *int*hands, *float* wager, *float* winning, String tableStatus) *throws* Exception { *try* { Game game = *em*.find(Game.*class*, gameId); GameLog gameLog = *new* GameLog(); gameLog.setGameId(game); gameLog.setMethodId(methodId); gameLog.setHands(hands); gameLog.setWager(wager); gameLog.setWinning(winning); gameLog.setTableStatus(tableStatus); *em*.getTransaction().begin(); *em*.persist(gameLog); *em*.getTransaction().commit(); } *catch* (Exception e) { e.printStackTrace(); *throw* e; } } } [/code] It works, but after stressing the GameHelper I realized that response time for updating data were too long. I tried clearing entity manager after commiting and response time increse a lot, perfect, but memory increase from 6M to 70M. Any idea of what is happening? Thanks
