[JBoss Seam] - Re: Lazy loading problem
by xtia004
By further probing my code, I found it is actually caused by em.clear at another component. i.e. when I select a row at dataTable, the following code is executed:
| InvoiceContacts invoiceContactsAction = (InvoiceContacts) Component.getInstance("invoiceContactsAction",
| ScopeType.SESSION);
| invoiceContactsAction.changeInvoice(getSelectedInvoice());
|
And code at component invoiceContactsAction is below:
| @Stateful
| @Name("invoiceContactsAction")
| @Scope(ScopeType.SESSION)
| public class InvoiceContactsAction implements InvoiceContacts {
|
| @PersistenceContext
| EntityManager em;
|
| ...
|
| public void changeInvoice(Invoice selectedInvoice) {
| this.selectedInvoice = selectedInvoice;
| tempList = null;
| invContacts = null;
| em.clear();
| }
|
| ...
| }
|
So the question turn out to be: Why does clearing the entity manager at a component make the entity bean retrieved by another component detached under this situation?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4004664#4004664
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4004664
19 years, 3 months
[Persistence, JBoss/CMP, Hibernate, Database] - How do I use auto-increment keys and CMP beans with XA trans
by johncook59
I use auto-increment keys for CMP EJBs. I am trying to port all our code from a local-tx-datasource to an xa-datasource. The problem is that the auto key generation is returning a null generated primary key, which causes the insert transaction to rollback. Here is an extract from the JBoss log:
00:21:48,656 INFO [RMI TCP Connection(6)-192.168.0.4] [STDOUT] Mon Jan 22 00:21:48 GMT 2007 DEBUG: Executing XA statement: XA START 0x4275737465722f3132,0x31,0x101
00:21:48,656 ERROR [RMI TCP Connection(6)-192.168.0.4] [CustomerManagerBean] Failed to create a customer: Primary key for created instance is null.
00:21:48,656 INFO [RMI TCP Connection(6)-192.168.0.4] [STDOUT] Mon Jan 22 00:21:48 GMT 2007 DEBUG: Executing XA statement: XA END 0x4275737465722f3132,0x31,0x101
00:21:48,656 INFO [RMI TCP Connection(6)-192.168.0.4] [STDOUT] Mon Jan 22 00:21:48 GMT 2007 DEBUG: Executing XA statement: XA ROLLBACK 0x4275737465722f3132,0x31,0x101
When I manually set the primary key, the insert completes as normal. This code worked perfectly with the non-XA datasource.
How do I use auto-increment keys with XA transactions?
The jbosscmp-jdbc.xml (generated from xdoclet) looks like this:
<ejb-name>Customer</ejb-name>
java:/BankDS
<datasource-mapping>mySQL</datasource-mapping>
<create-table>true</create-table>
<table-name>customer</table-name>
<cmp-field>
<field-name>id</field-name>
<column-name>customer_id</column-name>
<not-null/>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment/>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>
<cmp-field>
<field-name>password</field-name>
<column-name>password</column-name>
</cmp-field>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
The datasource deployment descriptor is
<xa-datasource>
<jndi-name>BankDS</jndi-name>
<xa-datasource-class>
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
</xa-datasource-class>
<xa-datasource-property name="URL">
jdbc:mysql://localhost:3306/bank
</xa-datasource-property>
<user-name>dbuser</user-name>
dbuser
<transaction-isolation>
TRANSACTION_READ_COMMITTED
</transaction-isolation>
<max-pool-size>5</max-pool-size>
<min-pool-size>0</min-pool-size>
<blocking-timeout-millis>2000</blocking-timeout-millis>
<idle-timeout-minutes>2</idle-timeout-minutes>
<track-connection-by-tx>true</track-connection-by-tx>
<new-connection-sql>set autocommit=false</new-connection-sql>
<no-tx-separate-pools>true</no-tx-separate-pools>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<type-mapping>mySQL</type-mapping>
</xa-datasource>
The target database is MySQL 5.0.27 and the Connector/J v5.0.4.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4004663#4004663
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4004663
19 years, 3 months
[Installation, Configuration & Deployment] - Jboss shut itself down, when I close a Apllet.
by este1212
Hi all,
I have a serious problem, and I find no solution.
I use PDFBox in my Webapplication and I have created with this Tool PDF Files, all is fine, by clicking a Button, I can open my PDF Files with help of PDFBox Methode. An applet will be oppening and I can read my pdf file, the Problem is, wenn I close my File (applet window), my Jboss Server shut itself down and I don't Know, what I musst do to prevent that.
Have someone an Idea, I will appreciate.
Thanks,
Radouane marjani
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4004662#4004662
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4004662
19 years, 3 months
[EJB 3.0] - Re: EntityManagerFactory not injected?
by akomulai
Oh no... just found this from project Glassfish FAQ:
Q. Can I use javax.persistence.Persistence.createEntityManagerFactory() to get hold of an EntityManagerFactory in my web application?
Yes, but this is not recommended because javax.persistence.Persistence.createEntityManagerFactory() is designed for use in a Java SE environment. In a Java EE environment, you can use dependency injection or JNDI lookup to access an EntityManagerFactory or an EntityManager as discussed earlier in this FAQ. Having said that, if you are using a web container like Tomcat 5.x which does not support Java Persistence API, then you have no option but to use this API. In such a case, we recommend you choose a container like GlassFish which supports the latest spec.
I'm using JBoss 4.0.5 which uses Tomcat 5.5 as web container. I guess it's goodbye JPA then? Do I have any alternatives left if I'm going to continue using JBoss?
What a mess :(
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4004651#4004651
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4004651
19 years, 3 months
[Beginners Corner] - Improper relationship betrween Entity-Beans
by puck
Hello out there,
I created for my small project two Entity-Beans which have a 1toN-relationship. In detail I have one ZugangsdatenBean (this is german but it doesn't matter what this means) and several TanBeans. From my point of view, there should be no problems. I show you the two beans. First the ZugangsdatenBean which is on the '1'-Edge:
@Entity
| @Table(name="ZUGANGSDATEN")
| public class ZugangsdatenBean implements Serializable
| {
| private static final long serialVersionUID = 1L;
| private String passwort;
| private String login_Name;
| private String pin;
| private Collection <TanBean> tans = new ArrayList<TanBean>();
|
| public ZugangsdatenBean() {}
|
| public ZugangsdatenBean( String passwort, String login_name, String pin )
| {
| this.passwort = passwort;
| this.login_Name = login_name;
| this.pin = pin;
| }
|
| @Column (name="PASSWORT")
| public String getpassword()
| {
| return this.passwort;
| }
|
| public void setpassword(String mypassword)
| {
| this.passwort = mypassword;
| }
|
| @Column (name="LOGIN")
| public String getlogin_name()
| {
| return this.login_Name;
| }
|
| public void setlogin_name(String mylogin)
| {
| this.login_Name = mylogin;
| }
|
| @Id
| @Column (name="PIN")
| public String getpin()
| {
| return this.pin;
| }
|
| public void setpin(String mypin)
| {
| this.pin = mypin;
| }
|
|
| @OneToMany (mappedBy="zugangsdatenbean",cascade=CascadeType.ALL, fetch=FetchType.EAGER)
| public Collection <TanBean> getAllTans()
| {
| return this.tans;
| }
|
| public void setTans(Collection <TanBean> mytan)
| {
| this.tans = mytan;
| }
|
|
| }
| And now the TanBean:
@Entity
| @Table(name="TAN")
| public class TanBean implements Serializable
| {
| private static final long serialVersionUID = 1L;
| private String nummer;
| private ZugangsdatenBean zugang = null;
|
| public TanBean (String mynummer)
| {
| this.nummer = mynummer;
| }
|
| @Id
| @Column (name="TNUMMER")
| @GeneratedValue ()
| public String getNummer()
| {
| return this.nummer;
| }
|
| public void setNummer(String mynummer)
| {
| this.nummer = mynummer;
| }
|
| @ManyToOne
| @JoinColumn(name="ZUGANGSDATEN")
| public ZugangsdatenBean getZugangsDaten()
| {
| return this.zugang;
| }
|
| public void setZugangsDaten(ZugangsdatenBean myzugang)
| {
| this.zugang = myzugang;
| }
| }
|
The Eclipse-Console give me this errors:
23:52:14,124 WARN [ServiceController] Problem starting service persistence.units:ear=TestBank.ear,jar=TestBankEJB.jar,unitName=chaos
| org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.chaos.tans.TanBean.zugangsdatenbean in org.chaos.zugangsdaten.ZugangsdatenBean.allTans
What is my misstake?
Than you
Gruss Christian
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4004650#4004650
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4004650
19 years, 3 months