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

Thread-safe problem while inserting(java.sql.SQLException: SQL String cannot be NULL ) #80

Open
gamtruliar opened this issue Nov 10, 2022 · 2 comments

Comments

@gamtruliar
Copy link

gamtruliar commented Nov 10, 2022

java.sql.SQLException: SQL String cannot be NULL

In StandardSqlMaker getPojoInfo:
private static ConcurrentHashMap<Class<?>, StandardPojoInfo> map = new ConcurrentHashMap<>();

public StandardPojoInfo getPojoInfo(Class<?> rowClass) {
	StandardPojoInfo pi = map.get(rowClass);
	if (pi == null) {
		pi = new StandardPojoInfo(rowClass);
		map.put(rowClass, pi);

		makeInsertSql(pi);
		makeUpsertSql(pi);
		makeUpdateSql(pi);
		makeSelectColumns(pi);
	}
	return pi;
}

There is some case that sql is not generated before using,
when doing many inserts in many threads at the first time.

When B thread get a StandardPojoInfo just after A thread finished the row of "map.put(rowClass, pi);"
B will get a StandardPojoInfo with null sql and then cause a exception.

It seem to need a lock for it. :)

@gamtruliar gamtruliar changed the title Thread-safe problem while inserting Thread-safe problem while inserting(java.sql.SQLException: SQL String cannot be NULL ) Nov 10, 2022
ccleve pushed a commit that referenced this issue Nov 10, 2022
@ccleve
Copy link
Member

ccleve commented Nov 10, 2022

Yup, I can see how this can happen. I just added a "synchronized" keyword to the method and pushed it to master. Version bumped to 1.0.6. Can you test it to see if it fixes the problem?

@ccleve
Copy link
Member

ccleve commented Nov 18, 2022

@gamtruliar Did the change fix your problem?

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