Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Ids not being used

My guess it is some kind of Spring configuration issue, but I'm no Spring
expert, so perhaps someone else can tell you more.  You could try the same
outside of Spring to see if the sequence ids get reused.  Also ensure that
you are using the lastest EclipseLink, I remember a similar issue but it was
either before EclipseLink 1.0, or 1.1.



sonavor wrote:
> 
> I have also run into this problem.  I don't know if it is a problem or my
> lack of understanding about the preallocated ids.  For now I have changed
> the allocation size to 1.  I was thinking that using a higher value like
> the default value of 50 would be more efficient (less times to read the ID
> table).
> 
> In my situation I am using EclipseLink with Spring and a Struts
> application.  My insert and update operations are only in a Spring
> business object and the entity manager is provided by Spring through this
> configuration in the Spring applicationContext.xml -
> 
> <!-- defines the JPA vendor adapter ... EclipseLink in this case -->
> <bean id="vendorAdapter"
> class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
>         <property name="databasePlatform"
> value="org.eclipse.persistence.platform.database.MySQLPlatformPlatform" />
>         <property name="showSql" value="true" />
> </bean>
> 
> <!-- defines the datasource from an expected JNDI name provided by the
> server -->
> <jee:jndi-lookup id="dataSource" jndi-name="jdbc/cimdb" />
> 
> <!-- defines the JPA EntityManagerFactory and injects the defined
> datasource -->
> <bean id="entityManagerFactory"
> class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
>         <property name="jpaVendorAdapter" ref="vendorAdapter"/>
>         <property name="dataSource" ref="dataSource" />
>         <property name="jpaPropertyMap">
>             <map>
>                 <entry key="eclipselink.jdbc.native-sql" value="true"/>
>                 <entry key="eclipselink.logging.level" value="FINEST"/>
>                 <entry key="eclipselink.logging.exceptions" value="true"/>
>                 <entry key="eclipselink.target-database" value="MYSQL"/>
>                 <entry key="eclipselink.weaving" value="static"/>
>             </map>
>         </property>
> </bean>
> 
> Then in my Spring business objects the EntityManager is injected with a
> method -
> //EntityManager will be auto-injected due to @PersistenceContext
> @PersistenceContext(unitName = "CiMJpaLibPU")
> private EntityManager em;
> public void setEntityManager(EntityManager em) {
>         this.em = em;
> }
> 
> Usage of the EntityManager in the Spring business class is then just like
> this -
> 
> Query q = em.createNamedQuery("MediaResolution.findAll");
> List<MediaResolution> rList = q.getResultList();
> 
> or in the case of an insert like this -
> 
> MediaListing ml = new MediaListing; // a JPA entity
> (pseudo code) ml.<set various attributes>
> em.persist(ml);
> 
> All of this works fine except that the generated primary keys jump by the
> default count of 50 unless I set the allocation size smaller.  As I do
> here -
> 
> @Id
> @GeneratedValue(generator="MLTable")
> @TableGenerator(name="MLTable", table="KEY_SEQUENCE",
>             pkColumnName="KEY_SEQ_NAME", valueColumnName="KEY_INDEX",
>             pkColumnValue="com.cim.jpa.MediaListing", allocationSize=1)
> @Basic(optional = false)
> @Column(name = "MEDIA_ID", nullable = false)
> private Integer mediaId;
> 
> I have noticed that in the case of a OneToMany relationship that while
> looping through and inserting the child records (i.e. media items for the
> MediaListing JPA class) that the MediaItems JPA children do get primary
> key values in increments of "1" even with the allocationSize set to the
> default 50.
> 
> The difference there is that the child records are being inserted at the
> same time as the parent and are all in one transaction.  While the parent
> inserts are always created in a new transaction.  Does that mean the
> Spring framework is creating a new EntityManager for each transaction
> then?
> 
> 
> 
> 
> 
> 
> 
> James Sutherland wrote:
>> 
>> 50 is the default preallocation size, but all the preallocated ids should
>> be used.  Are you creating a new EntityManagerFactory each time? Please
>> include your config.
>> 
>> 
>> 
>> cl333r wrote:
>>> 
>>> Folks, a simple example, after I insert one or more entities into the
>>> table the next id value starts with a 50 offset, and it happens every
>>> time. Hence it looks like a lot of id values will never be used. Is it
>>> true?
>>> Is there a "wiser" way to "spend" id numbers (except the "identity"
>>> solution)?
>>> 
>>> Using MySQL 5.0 on Ubuntu, JPA with EclipseLink. Happens for all
>>> generation types except IDENTITY but can't use it because it lets me
>>> know the ID of a newly created entity only after I commit it to the db.
>>> 
>> 
>> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Ids-not-being-used-tp24644801p24704131.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top