Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Andy Jefferson
    @andyjefferson
    @upost It may be possible to navigate through DN-specific classes to get to https://github.com/datanucleus/datanucleus-rdbms/blob/master/src/main/java/org/datanucleus/store/rdbms/ConnectionFactoryImpl.java and its "pool" field. But then again if you want to monitor such things you would be better off advised to create your own DBCP2 connection pool and pass that in, then you can do what you want with it.
    Krishna Prasad
    @krishnakittu

    CREATE TABLE `tiered_menu` ( `id` bigint(20) NOT NULL, `menuid` int(11) NOT NULL, `caption` varchar(100) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL, `index_column` int(11) NOT NULL, `parentid` bigint(20) NOT NULL, `class_column` varchar(230) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, PRIMARY KEY (`id`), KEY `menu_id_idx` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    I have a table design with the above structure to handle tiered menus. I need to know all the entries present in one menu, i achieve the same by native sql query but i need how to use joins in jDO

    Native sql query used for fetching desired result as below
    select b2.menuid from tiered_menu b1 left join tiered_menu b2 on b2.parentid = b1.parentid where b1.menuid = 32 and b2.menuid != -1 order by b2.index_column;

    Can you please refer some link where how can i use joins in JDO
    Andy Jefferson
    @andyjefferson
    JDO operates on objects and fields, not on arbitrary SQL concepts. JDOQL is an object-based query language. Suggest that you read documentation
    ryantrinh
    @ryantrinh
    Hi everyone! I'm trying to use JDO with MySQL database and I got the message like this: java.sql.SQLSyntaxErrorException: Table 'datanucleus.accounts' doesn't exist
    here are properties in persistence.xml: <properties>
    <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
    <property name="datanucleus.schema.autoCreateAll" value="true"/>
    <property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://localhost:3306/datanucleus"/>
    <property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.cj.jdbc.Driver"/>
    <property name="javax.jdo.option.ConnectionUserName" value="root"/>
    <property name="javax.jdo.option.ConnectionPassword" value="password"/>
    <property name="javax.jdo.option.Mapping" value="mysql"/> </properties>
    The Account Entity as well:

    @PersistenceCapable(table = "ACCOUNTS")
    public class Account {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    private String name;

    }

    Can anyone help me please. I've tried to use H2 database instead of MySQL and get the perfect result.
    Thank you very much
    Andy Jefferson
    @andyjefferson
    The log tells you what is happening, and how it is trying to create any required tables. Suggest that you inspect it
    ryantrinh
    @ryantrinh
    Thank you Andy. Finally I figure out the problem!
    Steve Springett
    @stevespringett
    FYI - https://www.datanucleus.org/ appears to be down.
    Norbert Bartels
    @nbartels
    hi all, I'm a bit confused about the version numbers. If I check the release notes, I see the core is 5.2.7, rdbms is 5.2.7, api-jdo is 5.2.6. Can I ignore the access platform version and simply have a look at the jar's version?
    Andy Jefferson
    @andyjefferson
    Individual plugins have their own lifecycles, just like they have since 2003 with JPOX. Accessplatform dep allows specification of a group that work together. Not hard.
    Norbert Bartels
    @nbartels
    👍
    Raymond Nathan
    @raymondnathan__twitter

    Hi there, I am new to JDO and testing out the capabilities.

    I have set up a project using mongodb, I can read & write non-nested domains from repositories.
    But domain which has nested objects during persists is throwing error like this:

    org.datanucleus.exceptions.NucleusUserException: Object with id "etc...." is managed by a different persistence manager.

    I couldn't find much information on the error above from the logs. I am using spring boot and have set-up the persistence manager factory as a bean. And auto-wired the PMF to all the @Repository classes like below:

    @Repository
    public class UserRepository {

    private final Logger logger = LoggerFactory.getLogger(UserRepository .class);
    
    @Autowired
    PersistenceManagerFactory pmf;
    
    private PersistenceManager pm() {
        return pmf.getPersistenceManager();
    }
    
    @SuppressWarnings("unchecked")
    public List<User> findAll() {
        Query query = pm().newQuery(User.class);
        List<User> users = (List<User>) query.execute();
        logger.info("Retrieved All User List: " + users);
        return users;
    }
    
    public User findByUserName(String userName)
    {
        JDOQLTypedQuery<User> query = pm().newJDOQLTypedQuery(User.class);
        QUser userQ = QUser.candidate();
        User user = query.filter(userQ.userName.equalsIgnoreCase(userName)).executeUnique();
        logger.info("Retrieved User with username ("+userName+"): " + user);
        return user;
    }
    
    public User save(User user) {
        user = pm().makePersistent(user);
        logger.info("Created User: " + user);
        return user;
    }

    }

    Andy Jefferson
    @andyjefferson
    If you don't DETACH an object from persistence then it is managed by a PersistenceManager. You cannot then pass it to a different PersistenceManager. That is nothing at all to do with MongoDB, just your (or Spring's) use of the JDO API. Work out why you aren't detaching objects
    Raymond Nathan
    @raymondnathan__twitter

    Thanks @andyjefferson I am able to get it working now after detaching the result from its persistenceManager after query.

    A question I still have, does the getPersistenceManager method from Factory class create a new PersistenceManager instance every time its called?

    Andy Jefferson
    @andyjefferson
    M W
    @ePortfel_gitlab
    @raymondnathan__twitter - I use org.springframework.orm.jdo.PersistenceManagerFactoryUtils to create and then get access to PersistenceManager with transactions in Spring.

    PersistenceManagerFactory is created also by Spring helper class, in AppContext it looks like this:

      <bean id="pmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
          <property name="jdoProperties">
              <props>
                 (...........)
              </props>
          </property>
      </bean>

    It works great for me however I do not know what the newest Spring offers on this.

    Raymond Nathan
    @raymondnathan__twitter

    @ePortfel_gitlab thank you, I am not using the PerssitenceManagerFactoryUtils from springframework.orm, but i had a look at the differences between these two, the spring LocalPersistenceManagerFactoryBean seems to only return create and return single instance, but Data Nucleus creates new instance every time.

    So I did this instead and seems to be working for me now

    @Bean
    public PersistenceManager persistenceManager(){
        logger.info("Setting up Persistence Manager Factory for " + mapping);
    
        Properties properties = new Properties();
        properties.setProperty("javax.jdo.PersistenceManagerFactoryClass",persistenceManagerFactoryClass);
        properties.setProperty("javax.jdo.option.ConnectionURL",connectionURL);
        properties.setProperty("javax.jdo.option.Mapping",mapping);
        properties.setProperty("datanucleus.schema.autoCreateAll",autoCreateAll);
        properties.setProperty("datanucleus.schema.validateTables",validateTables);
        properties.setProperty("datanucleus.schema.validateConstraints",validateConstraints);
    
        if(persistenceType.equalsIgnoreCase("sql"))
        {
            properties.setProperty("javax.jdo.option.ConnectionDriverName",connectionDriverName);
            properties.setProperty("javax.jdo.option.ConnectionUserName",connectionUserName);
            properties.setProperty("javax.jdo.option.ConnectionPassword",connectionPassword);
        }
        properties.forEach((k, v) -> logger.info("Key : " + k + ", Value : " + v));
    
        PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
        return pmf.getPersistenceManager();
    }
    Andy Jefferson
    @andyjefferson
    Hope you only ever need 1 PM if using that method! Creating a PMF is expensive
    Teargas
    @tear-gas
    Hello all,
    Should a SQL javax.jdo.Query.executeResultList(Class<R> resultCls) call be able to convert a SQL Date column to a LocalDate field on the result class?
    1 reply
    Jonathan Franchesco Torres Baca
    @jofrantoba
    Is there a way to disable level 1 cache only for one transaction?
    1 reply
    Andy Jefferson
    @andyjefferson
    @tear-gas A JDO "SQL" query is simply a wrapper around JDBC SQL statements. No conversion happens with JDBC, so it doesn't here. But then you can look at the code and see what it does
    Teargas
    @tear-gas
    @andyjefferson In the logs I see DEBUG [Query:61] () ResultObject set field=date using setDate() method after converting value which I think indicates the conversion is happening here: https://github.com/datanucleus/datanucleus-core/blob/master/src/main/java/org/datanucleus/store/query/QueryUtils.java#L467
    Jonathan Franchesco Torres Baca
    @jofrantoba
    @tear-gas setignorecache only disables cache l2
    Andy Jefferson
    @andyjefferson
    @jofrantoba No it doesnt.
    Andy Jefferson
    @andyjefferson
    Really depends on whether you want to ignore the cache when using a query, or when using getObjectById
    Jonathan Franchesco Torres Baca
    @jofrantoba
    minute 2:24
    setIdentity(false)
    Jonathan Franchesco Torres Baca
    @jofrantoba
    I'm doing a bulk insert and I don't need cache
    stay tuned to reply @andyjefferson
    Andy Jefferson
    @andyjefferson
    setIgnoreCache is for queries, as javadocs say clearly and as I've said. Bulk insert is nothing to do with that. The only use of an L1 cache in INSERT is to dump the object in the cache, so hardly significant
    Teargas
    @tear-gas
    @andyjefferson Would a change like this make sense relating to the SQL query Date/LocalDate conversion? This works for my purposes.
    https://github.com/datanucleus/datanucleus-core/compare/5.2...tear-gas:sqlDate-conversion
    Andy Jefferson
    @andyjefferson
    @tear-gas Without a testcase that shows the actual query no answer to that is possible. Yes, ClassUtils could convert more types (that are NOT in the JDO spec), but without seeing the sample query and knowing the call sequence, an answer is impossible and can't include anything. I personally would expect an SQL query with a result class (LocalDate) to use a ResultClassROF, and hence come through this code https://github.com/datanucleus/datanucleus-rdbms/blob/master/src/main/java/org/datanucleus/store/rdbms/query/ResultClassROF.java#L338
    Andy Jefferson
    @andyjefferson
    Also, ClassUtils.convertValue should be phased out and TypeConversionHelper.convertTo used instead
    Teargas
    @tear-gas
    Alright thanks. It might be an error on my part. I'll try to make a simplified test case.
    Andy Jefferson
    @andyjefferson
    @tear-gas Doesnt mean it is your error, just that I'd expect an exception from a different block of code. DN caters for specific "simple" types only (JDO spec list plus a few additions), so anything beyond those and it will likely need extra handling adding. There are always other types that it may be nice to add
    Andy Jefferson
    @andyjefferson
    See https://www.datanucleus.org/products/accessplatform_6_0/jdo/query.html#jdoql_resultclass for the simple types that are included in the JDO spec
    sailendrapavan
    @sailendrapavan
    Hi Team, I am new to datanucleus. I read the documentation but could find any code related inner query in JDOQl. Can some one please provide any source for this
    Andy Jefferson
    @andyjefferson
    Perhaps you haven't read much documentation, since there is this https://www.datanucleus.org/products/accessplatform_6_0/jdo/query.html#jdoql_subqueries
    sailendrapavan
    @sailendrapavan
    Sorry my question was to ask about inner join not inner query
    Andy Jefferson
    @andyjefferson
    This is JDOQL not SQL. You define relationships not arbitrary joins.
    sailendrapavan
    @sailendrapavan
    Thanks @andyjefferson I am able to do the requirement using the relations 👍