You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by Jm Seigneur <Je...@trustcomp.org> on 2006/12/05 19:52:13 UTC

how to create new users with HibernateUserManagerImpl

Hello,

I've been trying to create new roller users with 
HibernateUserManagerImpl as follows:

...
HibernatePersistenceStrategy strat = new HibernatePersistenceStrategy();
HibernateUserManagerImpl usersMan = new HibernateUserManagerImpl(strat);
UserData jm = usersMan.getUserByUserName("Jm"); //This works and I 
retrieve my roller account information
log.debug("Jm's email address is " + jm.getEmailAddress());

UserData newRollerUser = new UserData();
newRollerUser.setUserName(onlineUser.getMemberName());
newRollerUser.setPassword(memberPassword);
newRollerUser.setFullName(memberFirstname + " " + memberLastname);
newRollerUser.setEmailAddress(memberFirstEmail);
newRollerUser.setLocale(jm.getLocale());
newRollerUser.setTimeZone(jm.getTimeZone());
newRollerUser.setDateCreated(memberCreationDate);
newRollerUser.setEnabled(true);
usersMan.addUser(newRollerUser); //It seems to work, there is no 
exception but the new user is not created in the database
...

Any idea why I can read the content of the database but I cannot write 
in the database ?

Thanks,

Jm


Re: how to create new users with HibernateUserManagerImpl

Posted by Jm Seigneur <Je...@trustcomp.org>.
Dear Allen and Craig,

Thanks a million! I've followed the instructions below and it works now.

Allen Gilliland wrote:
> Ahhh, this is an excellent example of why it's important to impose tight 
> restrictions on some code to prevent inappropriate use.  It *should* be 
> hard (if not impossible) for someone to do 2 of the things below ... 1) 
> construct a specific persistence strategy class and 2) directly 
> instantiate a manager impl class :/
> 
> Jm,
> 
> the simple answer to your question is that you need to flush your 
> changes to the database by calling the flush() method on the active 
> Roller instance being used by the system.  Normally you would do this 
> via RollerFactory.getRoller().flush();
> 
> on a secondary note, you are actually doing the 2 things that I 
> mentioned above incorrectly.  you do not want to instantiate the 
> HibernateUserManagerImpl yourself, that will certainly cause problems. 
> Instead what you want to do is this ...
> 
> UserManager usersMan = RollerFactory.getRoller.getUserManager();
> 
> So, in pseudo code what you should be doing is this ...
> 
> umgr = roller.getUserManager() (as detailed above)
> newUser = new UserData()
> ... set user data ...
> umgr.addUser(newUser)
> roller.flush() // changes now go to DB
> 
> -- Allen
> 
> 
> Jm Seigneur wrote:
>> Hello,
>>
>> I've been trying to create new roller users with 
>> HibernateUserManagerImpl as follows:
>>
>> ...
>> HibernatePersistenceStrategy strat = new HibernatePersistenceStrategy();
>> HibernateUserManagerImpl usersMan = new HibernateUserManagerImpl(strat);
>> UserData jm = usersMan.getUserByUserName("Jm"); //This works and I 
>> retrieve my roller account information
>> log.debug("Jm's email address is " + jm.getEmailAddress());
>>
>> UserData newRollerUser = new UserData();
>> newRollerUser.setUserName(onlineUser.getMemberName());
>> newRollerUser.setPassword(memberPassword);
>> newRollerUser.setFullName(memberFirstname + " " + memberLastname);
>> newRollerUser.setEmailAddress(memberFirstEmail);
>> newRollerUser.setLocale(jm.getLocale());
>> newRollerUser.setTimeZone(jm.getTimeZone());
>> newRollerUser.setDateCreated(memberCreationDate);
>> newRollerUser.setEnabled(true);
>> usersMan.addUser(newRollerUser); //It seems to work, there is no 
>> exception but the new user is not created in the database
>> ...
>>
>> Any idea why I can read the content of the database but I cannot write 
>> in the database ?
>>
>> Thanks,
>>
>> Jm
>>


Re: how to create new users with HibernateUserManagerImpl

Posted by Allen Gilliland <al...@sun.com>.
Ahhh, this is an excellent example of why it's important to impose tight 
restrictions on some code to prevent inappropriate use.  It *should* be 
hard (if not impossible) for someone to do 2 of the things below ... 1) 
construct a specific persistence strategy class and 2) directly 
instantiate a manager impl class :/

Jm,

the simple answer to your question is that you need to flush your 
changes to the database by calling the flush() method on the active 
Roller instance being used by the system.  Normally you would do this 
via RollerFactory.getRoller().flush();

on a secondary note, you are actually doing the 2 things that I 
mentioned above incorrectly.  you do not want to instantiate the 
HibernateUserManagerImpl yourself, that will certainly cause problems. 
Instead what you want to do is this ...

UserManager usersMan = RollerFactory.getRoller.getUserManager();

So, in pseudo code what you should be doing is this ...

umgr = roller.getUserManager() (as detailed above)
newUser = new UserData()
... set user data ...
umgr.addUser(newUser)
roller.flush() // changes now go to DB

-- Allen


Jm Seigneur wrote:
> Hello,
> 
> I've been trying to create new roller users with 
> HibernateUserManagerImpl as follows:
> 
> ...
> HibernatePersistenceStrategy strat = new HibernatePersistenceStrategy();
> HibernateUserManagerImpl usersMan = new HibernateUserManagerImpl(strat);
> UserData jm = usersMan.getUserByUserName("Jm"); //This works and I 
> retrieve my roller account information
> log.debug("Jm's email address is " + jm.getEmailAddress());
> 
> UserData newRollerUser = new UserData();
> newRollerUser.setUserName(onlineUser.getMemberName());
> newRollerUser.setPassword(memberPassword);
> newRollerUser.setFullName(memberFirstname + " " + memberLastname);
> newRollerUser.setEmailAddress(memberFirstEmail);
> newRollerUser.setLocale(jm.getLocale());
> newRollerUser.setTimeZone(jm.getTimeZone());
> newRollerUser.setDateCreated(memberCreationDate);
> newRollerUser.setEnabled(true);
> usersMan.addUser(newRollerUser); //It seems to work, there is no 
> exception but the new user is not created in the database
> ...
> 
> Any idea why I can read the content of the database but I cannot write 
> in the database ?
> 
> Thanks,
> 
> Jm
> 

Re: how to create new users with HibernateUserManagerImpl

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Jm,

I guess you need to flush the new user using the Roller.flush() API  
or HibernatePersistenceStrategy.flush() depending on the environment.

Craig

On Dec 5, 2006, at 10:52 AM, Jm Seigneur wrote:

> Hello,
>
> I've been trying to create new roller users with  
> HibernateUserManagerImpl as follows:
>
> ...
> HibernatePersistenceStrategy strat = new  
> HibernatePersistenceStrategy();
> HibernateUserManagerImpl usersMan = new HibernateUserManagerImpl 
> (strat);
> UserData jm = usersMan.getUserByUserName("Jm"); //This works and I  
> retrieve my roller account information
> log.debug("Jm's email address is " + jm.getEmailAddress());
>
> UserData newRollerUser = new UserData();
> newRollerUser.setUserName(onlineUser.getMemberName());
> newRollerUser.setPassword(memberPassword);
> newRollerUser.setFullName(memberFirstname + " " + memberLastname);
> newRollerUser.setEmailAddress(memberFirstEmail);
> newRollerUser.setLocale(jm.getLocale());
> newRollerUser.setTimeZone(jm.getTimeZone());
> newRollerUser.setDateCreated(memberCreationDate);
> newRollerUser.setEnabled(true);
> usersMan.addUser(newRollerUser); //It seems to work, there is no  
> exception but the new user is not created in the database
> ...
>
> Any idea why I can read the content of the database but I cannot  
> write in the database ?
>
> Thanks,
>
> Jm
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!