1

当我通过 netbeans 访问 derby 并记录结果时,我得到了很好的数据,但是当我通过 PHP-Java Bridge 做完全相同的事情时,我没有得到任何数据。包装内:

com.m1sk.HelloBridge

 public static String backTest() throws Exception
    {
         BackendLink back = new BackendLink();
        return back.GetTourists();
    }

当通过 main 调用时,我得到如下信息:

[{<Json Representation of the only object in the database>}]

这很好,但是当我用 PHP-Java Bridge 调用这个函数时

<?
$test = new Java("com.m1sk.HelloBridge");
echo "!!<br>";
echo $test->backTest();
?>

我明白了

!!
[]

基本上它调用该函数,但由于某种原因,当它访问实际数据库时,它没有得到相同的东西!

编辑

*Backend_DAO_DB_impl:*

EntityManager em;
public Backend_DAO_DB_impl()
{
    String PersistenceName = "XYZ;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(PersistenceName);
    em =emf.createEntityManager();
}

public ArrayList<Tourist> GetTourists()
{
    Query q = em.createQuery("from Tourist");
    return (ArrayList<Tourist>) q.getResultList();
}

后端链接

public String GetTourists() throws Exception
{
     ArrayList<Tourist> tourists = back.GetTourists();
    JSONArray arr = new JSONArray();
    for(Tourist t : tourists)
    {
       arr.add(JSONConverter.touristToJSON(t));
    }
    return arr.toJSONString();
}

back 是 Backend_DAO_DB_impl 的对象 BackendLink 至少在 eclipse 中运行时有效。问题不在于 JSONConverter,我检查了。所以它必须在代码中更深一些,这意味着它可能在 derby 或 hibernate 中。

我目前的猜测是 netbeans 会自动做一些我没有用 java 桥做的事情。
编辑 这里的要求是日志:Catalina

Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.TouristSite
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity java5772_5140_9448_modelDB.TouristSite on table TouristSite
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.InsideSites
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.OutsideSites
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.TourReservation
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity java5772_5140_9448_modelDB.TourReservation on table TourReservation
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: java5772_5140_9448_modelDB.Tourist
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity java5772_5140_9448_modelDB.Tourist on table Tourist
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
**INFO: Hibernate Validator not found: ignoring**
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/sample
Jul 25, 2012 9:16:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=app, password=****, autocommit=true, release_mode=auto}
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Apache Derby, version: 10.8.1.2 - (1095077)
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.2.2.1 - (538595)
Jul 25, 2012 9:16:06 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.DerbyDialect
Jul 25, 2012 9:16:06 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Jul 25, 2012 9:16:06 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Jul 25, 2012 9:16:06 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: enabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Jul 25, 2012 9:16:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Jul 25, 2012 9:16:06 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Jul 25, 2012 9:16:06 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Jul 25, 2012 9:16:06 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Jul 25, 2012 9:16:06 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Jul 25, 2012 9:16:08 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete

其他的看起来还可以。我不太确定那条线。

4

0 回答 0