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

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