java - Spring - AutoWired object NullPointerExpection, Sequence Generator -
we have following error
java.lang.nullpointerexception @ sequence.mysequence.generate(mysequence.java:23)
my sequence generator
@component public class mysequence implements identifiergenerator { @autowired sequencedao sequencedao; public serializable generate(sessionimplementor session, object object) throws hibernateexception { <-- sequencedao.getnextvalue --> return sequencenextvalue; } }
sequencedao
public interface sequencedao { long getnextvalue(); }
sequencedaoimpl
@repository @transactional(readonly = false) public class sequencedaoimpl implements sequencedao { @autowired sessionfactory sessionfactory; @override @transactional(readonly = true) public long getnextvalue() { <-- getnextvalue --> return nextvalue; } }
config
<context:annotation-config /> <context:component-scan base-package="controller" /> <context:component-scan base-package="dao" /> <context:component-scan base-package="service" /> <context:component-scan base-package="sequence" /> <-- there mysequence
i don't know i'm doing wrong. rest controller, service, dao work without problems - @autowired works should. here don't know why happens.
all needs sequence generator (oracle database makes id string; therefore can't use generator directly database)
@id @genericgenerator(name="seqid", strategy="sequence.mysequence") @generatedvalue(generator="seqid") @column(name = "id", unique = true, nullable = false, length = 32) public string getid() { return this.id; }
any suggestions?
the generator class instanciated hibernate, not managed spring , no injection occurs. have implement directly code sequencedao
in method generate()
(you receive session in parameters can execute queries) or find mean access spring content through static method , sequencedao
it.
Comments
Post a Comment