2012-10-03 47 views
1

我想從使用JDO 3.1 API的持久化類生成表。如何使用JDO使用JDO持久化類到數據庫,出現錯誤

這是我的代碼:

class product 

@PersistenceCapable 
public class Product{ 

    @PrimaryKey 
    @Persistent(valueStrategy=IdGeneratorStrategy.INCREMENT) 
    public long id; 

    public String name = null; 
    public String description = null; 
    public double price = 0.0; 

    public Product(){} 

    public Product(String name, String desc, double price) 
    { 
     this.name = name; 
     this.description = desc; 
     this.price = price; 
    } 

這是我的主:

public static void main(String[] args) { 

     JDOEnhancer enhancer = JDOHelper.getEnhancer(); 
      enhancer.setVerbose(true); 
      enhancer.addClasses(Product.class.getName()); 
     // enhancer.addPersistenceUnit("OnlineStore"); 
      // add entities to be enhanced to this list... 
      enhancer.enhance(); 


     Properties properties = new Properties(); 
     properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", 
         "org.datanucleus.api.jdo.JDOPersistenceManagerFactory"); 



     properties.setProperty("datanucleus.ConnectionDriverName","com.mysql.jdbc.Driver"); 
     properties.setProperty("datanucleus.ConnectionURL","jdbc:mysql://localhost/example"); 
     properties.setProperty("datanucleus.ConnectionUserName","root"); 
     properties.setProperty("datanucleus.ConnectionPassword","root");  

     PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties); 
     PersistenceManager pm = pmf.getPersistenceManager(); 


     Transaction tx=pm.currentTransaction(); 
     try 
     { 
      tx.begin(); 
      Product product = new Product("Sony Discman", "A standard discman from Sony", 49.99); 
      pm.makePersistent(new Product()); 
      tx.commit(); 
     } 
     finally 
     { 
      if (tx.isActive()) 
      { 
       tx.rollback(); 
      } 
      pm.close(); 
     } 

    } 

我有一個錯誤:

No hay ningun generador de valor para la estrategia "custom" para este base de datos. Por favor, lee en la documentaci�n sobre las estrategias que esta apoyado para este base de datos. 
org.datanucleus.exceptions.NucleusUserException: No hay ningun generador de valor para la estrategia "custom" para este base de datos. Por favor, lee en la documentaci�n sobre las estrategias que esta apoyado para este base de datos. 
    at org.datanucleus.store.AbstractStoreManager.getStrategyValue(AbstractStoreManager.java:1564) 
    at org.datanucleus.state.JDOStateManager.populateStrategyFields(JDOStateManager.java:690) 
    at org.datanucleus.state.JDOStateManager.initialiseForPersistentNew(JDOStateManager.java:362) 
    at org.datanucleus.state.StateManagerFactory.newForPersistentNew(StateManagerFactory.java:187) 
    at org.datanucleus.state.ObjectProviderFactory.newForPersistentNew(ObjectProviderFactory.java:145) 
    at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1895) 
    at org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1745) 
    at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1593) 
    at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:731) 
    at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:756) 
    at com.test.Main.main(Main.java:47) 

有沒有人使用JDO類和MySQL映射?我在運行時增強類,而不是在構建時。

+0

沒有habla espanol。 –

回答

相關問題