Kalaupun exceptionnya ditangkap, percuma. Karena program masuk ke blok try
dengan sukses (halaman "success" yang terbuka tanpa ada error message pada
server log). Namun tidak ada perubahan pada data sama sekali. Kenapa ,ya?
idcustomer = Integer.parseInt(session.getIdentifier(customer).toString());
userInfo.setCustomerid(idcustomer);
userInfo.setIslogin("false");
session.save(userInfo);
//perintah akhir untuk mensukseskan penyimpanan data
try {
session.getTransaction().commit();
// kirim email notifikasi
SimpleEmail email = new SimpleEmail();
email.setHostName("192.168.168.1");
email.addTo(customer.getEmail(), customer.getFirstname());
email.setFrom("[EMAIL PROTECTED]", "putri");
email.setSubject("Registrasi Berhasil");
email.setMsg("Proses registrasi Anda berhasil. Selamat
bergabung.");
email.send();
SUCCESS = "success";
} catch (Exception ex) {
session.getTransaction().rollback();
SUCCESS = "failed";
}
On Sat, Nov 29, 2008 at 5:12 PM, sutarsa giri <[EMAIL PROTECTED]>wrote:
> wah,
> kalau seperti ini masalahnya sih sulit di deteksi, karena exception tidak
> di log sama sekali. catch cuma seperti ini :
> __________________________________________
> catch (Exception ex) {
> session.getTransaction().
> rollback();
> SUCCESS = "failed";
> }
> __________________________________________
>
> saya sarankan ini di log, misalnya dengan kalau denan JCL,
>
> Log logger = LogFactory.getLog(ActionForward.class);
>
> logger.error(exc);
> atau kalau mau lebih memudahkan misalnya tambahkan comment misalnya
> logger.error("gagal melakukan sesuatu karena ; " + exc.getMessage())
>
> silakan di coba, semoga bisa membantu
>
> salam,
> gede sutarsa
>
>
> On Fri, Nov 28, 2008 at 4:58 AM, PUTRI CHAIRINA <[EMAIL PROTECTED]>wrote:
>
>> Oh ya, setelah mencoba page registrasi, pada glassfish ada tambahan
>> pesan :
>>
>> InitialContext did not implement EventContext
>> Hibernate: select product0_.PRODUCTID as PRODUCTID0_,
>> product0_.PRODUCTNAME as PRODUCTN2_0_, product0_.CATEGORY as CATEGORY0_,
>> product0_.PRICE as PRICE0_, product0_.STOCK as STOCK0_, product0_.PROVIDER
>> as PROVIDER0_, product0_.IMAGE as IMAGE0_, product0_.UNIT as UNIT0_,
>> product0_.DISCOUNT as DISCOUNT0_ from PRODUCT2 product0_
>> Hibernate: select product0_.PRODUCTID as PRODUCTID0_,
>> product0_.PRODUCTNAME as PRODUCTN2_0_, product0_.CATEGORY as CATEGORY0_,
>> product0_.PRICE as PRICE0_, product0_.STOCK as STOCK0_, product0_.PROVIDER
>> as PROVIDER0_, product0_.IMAGE as IMAGE0_, product0_.UNIT as UNIT0_,
>> product0_.DISCOUNT as DISCOUNT0_ from PRODUCT2 product0_ where
>> product0_.PRODUCTID=2
>>
>> Kenapa dan bagaimana cara menyelesaikannya? Terima kasih.
>>
>>
>> On Fri, Nov 28, 2008 at 5:52 AM, PUTRI CHAIRINA <[EMAIL PROTECTED]
>> > wrote:
>>
>>> Pagi semuanya, saya mau memasukkan data dari form registrasi. (Pagi-pagi
>>> udah ngasih masalah,nih..) Tetapi kenapa tidak berhasil, ya? Ada yang bisa
>>> membantu saya? Terima kasih.
>>>
>>> *Pada Glassfish hanya ada pesan :*
>>>
>>> deployed with moduleid = AgricultureShop
>>> Tiles definition factory loaded for module ''.
>>> Loading validation rules file from '/WEB-INF/validator-rules.xml'
>>> Loading validation rules file from '/WEB-INF/validation.xml'
>>> Tiles definition factory found for request processor ''.
>>> Hibernate 3.2.5
>>> hibernate.properties not found
>>> Bytecode provider name : cglib
>>> using JDK 1.4 java.sql.Timestamp handling
>>> configuring from resource: /hibernate.cfg.xml
>>> Configuration resource: /hibernate.cfg.xml
>>> Reading mappings from resource : Product.hbm.xml
>>> Mapping class: com.putri.model.Product -> PRODUCT2
>>> Reading mappings from resource : Customer.hbm.xml
>>> Mapping class: com.putri.model.Customer -> CUSTOMER2
>>> Reading mappings from resource : Address.hbm.xml
>>> Mapping class: com.putri.model.Address -> ADDRESS2
>>> Reading mappings from resource : UserInfo.hbm.xml
>>> Mapping class: com.putri.model.UserInfo -> USERINFO2
>>> Configured SessionFactory: session1
>>> Using Hibernate built-in connection pool (not for production use!)
>>> Hibernate connection pool size: 20
>>> autocommit mode: false
>>> using driver: org.apache.derby.jdbc.ClientDriver at URL:
>>> jdbc:derby://localhost:1527/sample
>>> connection properties: {user=app, password=****}
>>> cleaning up connection pool: jdbc:derby://localhost:1527/sample
>>> RDBMS: Apache Derby, version: 10.3.1.4 - (561794)
>>> JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.2.2.1-
>>> (538595)
>>> Using dialect: org.hibernate.dialect.DerbyDialect
>>> Using default transaction strategy (direct JDBC transactions)
>>> No TransactionManagerLookup configured (in JTA environment, use of
>>> read-write or transactional second-level cache is not recommended)
>>> Automatic flush during beforeCompletion(): disabled
>>> Automatic session close at end of transaction: disabled
>>> Scrollable result sets: enabled
>>> JDBC3 getGeneratedKeys(): disabled
>>> Connection release mode: auto
>>> Default batch fetch size: 1
>>> Generate SQL with comments: disabled
>>> Order SQL updates by primary key: disabled
>>> Order SQL inserts for batching: disabled
>>> Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
>>> Using ASTQueryTranslatorFactory
>>> Query language substitutions: {}
>>> JPA-QL strict compliance: disabled
>>> Second-level cache: enabled
>>> Query cache: disabled
>>> Cache provider: org.hibernate.cache.NoCacheProvider
>>> Optimize cache for minimal puts: disabled
>>> Structured second-level cache entries: disabled
>>> Echoing all SQL to stdout
>>> Statistics: disabled
>>> Deleted entity synthetic identifier rollback: disabled
>>> Default entity-mode: pojo
>>> Named query checking : enabled
>>> building session factory
>>> Factory name: session1
>>> JNDI InitialContext properties:{}
>>> Bound factory to JNDI name: session1
>>> InitialContext did not implement EventContext
>>>
>>> *Action Struts yang saya buat :*
>>>
>>> public class RegisterAction extends org.apache.struts.action.Action {
>>>
>>> HibernateUtil hibernateUtil = new HibernateUtil();
>>> Customer customer;
>>> Address address;
>>> UserInfo userInfo;
>>> String SUCCESS;
>>>
>>> public ActionForward execute(ActionMapping mapping, ActionForm form,
>>> HttpServletRequest request, HttpServletResponse response)
>>> throws Exception {
>>>
>>> //
>>> HttpSession sessionApp = request.getSession();
>>> ShoppingCart cart = (ShoppingCart)
>>> sessionApp.getAttribute("cart");
>>> if (cart == null) {
>>> sessionApp.setAttribute("totalShoppingItems", 0);
>>> } else {
>>> sessionApp.setAttribute("totalShoppingItems",
>>> cart.getNumberOfItems());
>>> }
>>>
>>> RegisterBeanAutomation bean = (RegisterBeanAutomation) form;
>>>
>>> //alokasi ke memori
>>> customer = new Customer();
>>> address = new Address();
>>> userInfo = new UserInfo();
>>>
>>> //simpan properti dari tiap objek
>>> PropertyUtils.copyProperties(customer, bean);
>>> PropertyUtils.copyProperties(address, bean);
>>> PropertyUtils.copyProperties(userInfo, bean);
>>>
>>> //enkripsi password, lalu disimpan
>>> UserAuthentification userAuth = new UserAuthentification();
>>> userInfo.setPassword(userAuth.encrypt(userInfo.getPassword()));
>>>
>>> //buat session factory
>>> SessionFactory factory = hibernateUtil.getSessionFactory();
>>> Session session = factory.getCurrentSession();
>>> session.beginTransaction();
>>>
>>> session.save(customer);
>>>
>>> int idcustomer =
>>> Integer.parseInt(session.getIdentifier(customer).toString());
>>> address.setTypeaddress("Home");
>>> address.setCustomerid(idcustomer);
>>> session.save(address);
>>>
>>>
>>> idcustomer =
>>> Integer.parseInt(session.getIdentifier(customer).toString());
>>> userInfo.setCustomerid(idcustomer);
>>> userInfo.setIslogin("false");
>>> session.save(userInfo);
>>>
>>> session.getTransaction().commit();
>>> SUCCESS = "success";
>>> //perintah akhir untuk mensukseskan penyimpanan data
>>> try {
>>> session.getTransaction().commit();
>>> // kirim email notifikasi
>>> SimpleEmail email = new SimpleEmail();
>>> email.setHostName("192.168.168.1");
>>> email.addTo(customer.getEmail(), customer.getFirstname());
>>> email.setFrom("[EMAIL PROTECTED]", "putri");
>>> email.setSubject("Registrasi Berhasil");
>>> email.setMsg("Proses registrasi Anda berhasil. Selamat
>>> bergabung.");
>>> email.send();
>>> SUCCESS = "success";
>>>
>>> } catch (Exception ex) {
>>> session.getTransaction().rollback();
>>> SUCCESS = "failed";
>>> }
>>>
>>> return mapping.findForward(SUCCESS);
>>>
>>> }
>>> }
>>>
>>>
>>
>
>