Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used in Hbase: java.lang.IllegalArgumentException: Can not set int field com.zju.edu.entity.User.userId to com.zju.edu.entity.User #1024

Open
lmy86263 opened this issue Aug 15, 2018 · 3 comments

Comments

@lmy86263
Copy link

hello, when I use it in hbase, some exception has appeared as title issued.

1. First, my entity class like this:

public class User
{
    public User(){}

    @Id
    @Column(name = "rowkey")
    private int userId;

    @Column(name = "PERSON_NAME")
    private String userName;

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
}

2. and my persistence like this:

<persistence-unit name="hbase_pu">
		<provider>com.impetus.kundera.KunderaPersistence</provider>
		<properties>
			<property name="kundera.nodes" value="localhost" />
			<property name="kundera.port" value="16010" />
			<property name="kundera.keyspace" value="KunderaExamples" />
			<property name="kundera.dialect" value="hbase" />
			<property name="kundera.ddl.auto.prepare" value="create" />
			<property name="kundera.client.lookup.class" value="com.impetus.client.hbase.HBaseClientFactory" />
		</properties>
	</persistence-unit>

3. my persist code is like this:

User user = new User();
user.setUserId(1);
user.setUserName("John");
entityManager().persist(user);

4. and the phenomenon is like this: I can connect to zookeeper server and HMaster, and create a table in hbase, but I can not persist any entity.

5. the exception log like this:

java.lang.IllegalArgumentException: Can not set int field com.zju.edu.entity.User.userId to com.zju.edu.entity.User
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_65]
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_65]
	at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58) ~[na:1.8.0_65]
	at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:56) ~[na:1.8.0_65]
	at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:36) ~[na:1.8.0_65]
	at java.lang.reflect.Field.get(Field.java:393) ~[na:1.8.0_65]
	at com.impetus.kundera.property.PropertyAccessorHelper.getObject(PropertyAccessorHelper.java:140) ~[kundera-core-3.13.jar:na]
	at com.impetus.kundera.property.PropertyAccessorHelper.getId(PropertyAccessorHelper.java:245) ~[kundera-core-3.13.jar:na]
	at com.impetus.kundera.graph.GraphGenerator.onPreChecks(GraphGenerator.java:223) ~[kundera-core-3.13.jar:na]
	at com.impetus.kundera.graph.GraphGenerator.generate(GraphGenerator.java:127) ~[kundera-core-3.13.jar:na]
	at com.impetus.kundera.graph.GraphGenerator.generateGraph(GraphGenerator.java:78) ~[kundera-core-3.13.jar:na]
	at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:130) ~[kundera-core-3.13.jar:na]
	at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:174) ~[kundera-core-3.13.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350) ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at com.sun.proxy.$Proxy88.persist(Unknown Source) ~[na:na]

6. something else that can be helpful

I found the error always appear about the field which is annotated by @id, I hope it can be helpful.

@devender-yadav
Copy link
Contributor

@lmy86263 what Kundera version are you using? Try latest version i.e. 3.13 (if using older version).

You can try sample project - https://github.com/Impetus/Kundera#sample-projects

@lmy86263
Copy link
Author

lmy86263 commented Aug 16, 2018

@devender-yadav yes, it works with the examples. But, I want to use it in spring framework. And I follow the tutorial about integration with spring step by step, so the exception appears.

And the Kundera version is the latest version 3.13, and I use spring boot 2.0, the related configuration like this:

@Configuration
public class KunderaConfig {
    @Bean
    public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
        LocalContainerEntityManagerFactoryBean entityMF = new LocalContainerEntityManagerFactoryBean();
        entityMF.setPersistenceUnitName("hbase_pu");
        entityMF.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
        return entityMF;
    }

    @Bean
    public PersistenceAnnotationBeanPostProcessor persistenceAnnotationBeanPostProcessor() {
        return new PersistenceAnnotationBeanPostProcessor();
    }

    @Bean
    public DefaultPersistenceUnitManager defaultPersistenceUnitManager() {
        DefaultPersistenceUnitManager persistenceUM = new DefaultPersistenceUnitManager();
        persistenceUM.setPersistenceXmlLocation("classpath*:META-INF/persistence-temp.xml");
        return persistenceUM;
    }
}

and the client code is like this:


    @Resource
    @PersistenceContext(unitName = "hbase_pu", type = PersistenceContextType.EXTENDED)
    public EntityManager em;
    
    public void persist(){
        User user = new User();
        user.setUserId(1);
        user.setUserName("John");

        em.persist(user);
        em.close();

    }

by the way, my hbase server is running in standalone mode.

@devender-yadav
Copy link
Contributor

@lmy86263 running in standalone mode shouldn't be a problem. could you please share sample project so that I can reproduce at my end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants