Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] Dynamically dropping and creating indexes

My humble apologies; I've gone back to test it and it now works fine.

Mark

Mark Millman | Mizar, LLC | mark.millman@xxxxxxxxx | www.mizar.com | (360)
945-2643
589 S Beach Rd. | Point Roberts, WA 98281

The information contained in this communication may be confidential, is
intended only for the use of the recipient(s) named above, and may be
legally privileged. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution, or
copying of this communication, or any of its contents, is strictly
prohibited. If you have received this communication in error, please return
it to the sender immediately and delete the original message and any copy of
it from your computer system. If you have any questions concerning this
message, please contact the sender.


-----Original Message-----
From: Gordon Yorke [mailto:gordon.yorke@xxxxxxxxxx] 
Sent: Friday, March 20, 2009 10:05 AM
To: mark.millman@xxxxxxxxx; EclipseLink User Discussions
Subject: Re: [eclipselink-users] Dynamically dropping and creating indexes

Have you reviewed the SQL that is generated?  Is it correct?
This is the recommended way of executing SQL.  What does your JDBC code 
look like? 
--Gordon

Mark Millman wrote:
> I want to be able to drop and create indexes at runtime so I tried to call
> Query.executeUpdate(sql) to accomplish this as follows:
>
>   public void executeDDL(String sql) throws PersistenceException {
>     EntityManager em = getEm();
>     final EntityTransaction et = em.getTransaction();
>     try {
>       et.begin();
>       em.clear();
>       Query ddl = getEm().createNativeQuery(sql);
>       int c = ddl.executeUpdate();
>       et.commit();
>     } catch (Exception e) {
>       _Logger.error("executeDDL failure of "+sql, e);
>       if (et != null && et.isActive()) {
>         et.rollback();
>       }
>       throw new PersistenceException("executeDDL failure: " +
> e.getCause().getLocalizedMessage(), e.getCause());
>     }
>   }
>
> And it worked ... but only once.  I could drop an index and create it
again
> but when I attempted to drop it a second time it returned without error
but
> the index wasn't dropped.  Ditto on creating it a second time, even though
> it existed it didn't throw any errors.
>
> Is there some better way to execute DDL at runtime or should I continue to
> perform these actions using JDBC, which is my current work around.
>
> Thanks, Mark
>
> p.s.
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
> running in WebLogic Server 10.3.0
>
> p.p.s   If I called Query.executeUpdate outside of an EntityTransaction it
> throws an error telling me I require a Transaction, which makes sense.
>
> Mark Millman | Mizar, LLC | mark.millman@xxxxxxxxx | www.mizar.com | (360)
> 945-2643
> 589 S Beach Rd. | Point Roberts, WA 98281
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>   



Back to the top