[JBoss Tools (users)] - Re: JBoss Tools Documentation
by bdlink
I guess what I would find useful (after trying generate-entries on an earlier test project) would be something that either maps entities to tables, or generates tables from entities, but since in either case, the mapping probably needs some ability for human guidance. For example, given a schema, a tool can not guess whether I want to navigate both directions, may not be able to guess if a relation is 1-1 or 1-n (at least generate entities turned my 1-1 relationships to 1-n, even though I had put unique constraints on the table to force only one interpretation). Another example which could not be guessed from the schema is if I want the entities to be in an inheritance relationship.
My main issue with generate entities is not that it guesses wrong, but that after hand-fixing the entities, the other artifacts need massive editing, and it is hard to be sure I have found everything. If I restart the project (to perhaps use a new version of the tools or seam) I have to go through the entire process again.
As well, the CRUD pages generate-entities creates are interesting from the standpoint of a demo, and for seeing how they are done, however, I am not convinced I would want these pages for creating and updating generated for each table (For example, that is not how to handle an associative table that implements a many-many relationship). So generate-entities seems to create a lot of things that have to be edited/deleted. (apropos names, it generates a lot more than entities)
I may be wrong in the above feelings, but in any case, generating EJB3 entities/session beans is a useful separate thing from getting everything seam generate entities creates.
Is there a place that the use cases for RHDS are described?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103398#4103398
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103398
18 years, 8 months
[EJB 3.0] - Relationship Only Saving 1 Child Object
by ddurst@mechdrives.com
I am running JBoss 4.0.4.GA and JDK 1.5.0_06.
I have a One To Many relationship Order->OrderLine
I collect all the OrderLines and add them to the order and then
call the session facade to save. Unfortunately only one of my OrderLines
gets persisted. Can anyone tell me why?
Code to save Order
| order.setOrderLines(orderLines);
| OrderFCD obf = new OrderFCD();
| order = obf.create(order);
|
Order
| package beltmasta.ejb.persistance;
|
| import java.io.Serializable;
| import java.util.Calendar;
| import java.util.Collection;
| import java.util.Vector;
| import javax.persistence.CascadeType;
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.NamedQueries;
| import javax.persistence.NamedQuery;
| import javax.persistence.OneToMany;
| import javax.persistence.OneToOne;
| import javax.persistence.Table;
| import javax.persistence.Temporal;
| import javax.persistence.TemporalType;
|
| /**
| * Entity class Order
| * @author David
| */
| @Entity
| @Table(name="belt_order")
| @NamedQueries( {
| @NamedQuery(name="order.getOrdersByCustomer", query="select object(o) from Order as o where o.status = 'O' and o.orderHeader.customer = :customer"),
| @NamedQuery(name="order.getQuotesByCustomer", query="select object(o) from Order as o where o.status = 'B' and o.orderHeader.customer = :customer"),
| @NamedQuery(name="order.getInvoicesByCustomer", query="select object(o) from Order as o where o.status = 'I' and o.orderHeader.customer = :customer"),
| @NamedQuery(name="order.getHoldOrdersByCustomer", query="select object(o) from Order as o where o.status = 'H' and o.orderHeader.customer = :customer"),
| @NamedQuery(name="order.getConsignmentOrdersByCustomer", query="select object(o) from Order as o where o.status = 'C' and o.orderHeader.customer = :customer")
| })
| public class Order implements Serializable {
| public static String BID = "B";
| public static String ORDER = "O";
| public static String INVOICE = "I";
| public static String HOLD = "H";
| public static String CONSIGNMENT = "C";
|
|
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| private Long id;
| private String eclipseId;
| @Column(length = 1)
| private String status;
| @Temporal(TemporalType.TIMESTAMP)
| private Calendar quoteTime;
| @Temporal(TemporalType.TIMESTAMP)
| private Calendar orderTime;
| @Temporal(TemporalType.TIMESTAMP)
| private Calendar invoiceTime;
|
| @OneToOne(cascade = CascadeType.ALL)
| private OrderHeader orderHeader;
|
| @OneToMany(mappedBy="parentOrder", cascade=CascadeType.ALL)
| private Collection <OrderLine>orderLines = new Vector<OrderLine>();
|
| public Order() {
| }
|
|
| //<editor-fold defaultstate="collapsed" desc="Properties Accessors">
| public Long getId() {
| return this.id;
| }
| public void setId(Long id) {
| this.id = id;
| }
| public String getEclipseId() {
| return eclipseId;
| }
| public void setEclipseId(String eclipseId) {
| this.eclipseId = eclipseId;
| }
| public String getStatus() {
| return status;
| }
| public void setStatus(String status) {
| this.status = status;
| }
| public Calendar getQuoteTime() {
| return quoteTime;
| }
| public void setQuoteTime(Calendar quoteTime) {
| this.quoteTime = quoteTime;
| }
| public Calendar getOrderTime() {
| return orderTime;
| }
| public void setOrderTime(Calendar orderTime) {
| this.orderTime = orderTime;
| }
| public Calendar getInvoiceTime() {
| return invoiceTime;
| }
| public void setInvoiceTime(Calendar invoiceTime) {
| this.invoiceTime = invoiceTime;
| }
|
| //</editor-fold>
| //<editor-fold defaultstate="collapsed" desc="Method Overides">
| @Override
| public int hashCode() {
| int hash = 0;
| hash += (this.id != null ? this.id.hashCode() : 0);
| return hash;
| }
| @Override
| public boolean equals(Object object) {
| // TODO: Warning - this method won't work in the case the id fields are not set
| if (!(object instanceof Order)) {
| return false;
| }
| Order other = (Order)object;
| if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
| return true;
| }
| @Override
| public String toString() {
| return id.toString();
| }
|
| //</editor-fold>
| //<editor-fold defaultstate="collapsed" desc="Logic Methods">
| public void setQuoted() {
| this.setQuoteTime(Calendar.getInstance());
| }
| public void setOrdered() {
| this.setOrderTime(Calendar.getInstance());
| }
| public void setInvoiced(){
| this.setInvoiceTime(Calendar.getInstance());
| }
| //</editor-fold>
| //<editor-fold defaultstate="collapsed" desc="Relationships">
| public OrderHeader getOrderHeader() {
| return orderHeader;
| }
| public void setOrderHeader(OrderHeader orderHeader) {
| this.orderHeader = orderHeader;
| }
| public Collection<OrderLine> getOrderLines() {
| return orderLines;
| }
| public void setOrderLines(Collection<OrderLine> orderLines) {
| System.out.println("Before # of orderlines: "+orderLines.size());
| this.orderLines = new Vector(orderLines);
| System.out.println("After # of orderlines: "+this.orderLines.size());
|
| }
| //</editor-fold>
|
| }
|
OrderLine
| package beltmasta.ejb.persistance;
|
| import beltmasta.ejb.persistance.embeddable.LineQuantity;
| import beltmasta.ejb.persistance.embeddable.PriceCost;
| import java.io.Serializable;
| import java.util.ArrayList;
| import java.util.Calendar;
| import java.util.Collection;
| import javax.persistence.AttributeOverride;
| import javax.persistence.AttributeOverrides;
| import javax.persistence.CascadeType;
| import javax.persistence.Column;
| import javax.persistence.Embedded;
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.JoinColumn;
| import javax.persistence.ManyToOne;
| import javax.persistence.NamedQueries;
| import javax.persistence.NamedQuery;
| import javax.persistence.OneToMany;
| import javax.persistence.OneToOne;
| import javax.persistence.Table;
| import javax.persistence.Temporal;
| import javax.persistence.TemporalType;
|
| /**
| * Entity class OrderLine
| * @author David
| */
| @Entity
| @Table(name="belt_order_line")
| @NamedQueries( {
| @NamedQuery(name="orderline.bybelttype.bydaterange", query="select object(ol) from OrderLine as ol where ol.belt.beltType = :type and (ol.parentOrder.orderTime >= :startDate and ol.parentOrder.orderTime <= :endDate)")
| })
|
| public class OrderLine implements Serializable {
| public static String PICKUP = "P";
| public static String SHIP_WHEN_COMP = "H";
| public static String SHIP_WHEN_SPEC = "S";
| public static String CALL_WHEN_COMP = "C";
| public static String CALL_WHEN_SPEC = "W";
| public static String CANCEL = "X";
| public static String INVOICE = "I";
| public static String CONSIGN = "N";
| public static String HOLD = "L";
|
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| private Long id;
| private String lineStatus = OrderLine.SHIP_WHEN_COMP;
| @Temporal(TemporalType.TIMESTAMP)
| private Calendar requiredDate;
|
| @Embedded
| @AttributeOverrides({
| @AttributeOverride(name = "order", column=@Column(name="order_qty")),
| @AttributeOverride(name = "process", column=@Column(name="process_qty")),
| @AttributeOverride(name = "released", column=@Column(name="released_qty"))
| })
| private LineQuantity quantity;
| @Embedded
| private PriceCost priceCost;
| @OneToOne(cascade = CascadeType.ALL)
| private Belt belt;
| @ManyToOne
| @JoinColumn(name="parentOrder")
| private Order parentOrder;
| @OneToMany(mappedBy="orderLine", cascade = CascadeType.ALL)
| private Collection <SlabAssignment>slabAssignments = new ArrayList<SlabAssignment>();
| public OrderLine() {
| requiredDate = Calendar.getInstance();
| requiredDate.set(Calendar.DATE,requiredDate.get(Calendar.DATE)+3);
| }
| //<editor-fold defaultstate="collapsed" desc="Properties Accessors">
| public Long getId() {
| return this.id;
| }
| public void setId(Long id) {
| this.id = id;
| }
| public String getLineStatus() {
| return lineStatus;
| }
| public void setLineStatus(String lineStatus) {
| if(lineStatus.equals(OrderLine.PICKUP) ||
| lineStatus.equals(OrderLine.SHIP_WHEN_COMP) ||
| lineStatus.equals(OrderLine.SHIP_WHEN_SPEC) ||
| lineStatus.equals(OrderLine.CALL_WHEN_SPEC) ||
| lineStatus.equals(OrderLine.CALL_WHEN_COMP) ||
| lineStatus.equals(OrderLine.CANCEL) ||
| lineStatus.equals(OrderLine.INVOICE)||
| lineStatus.equals(OrderLine.CONSIGN)||
| lineStatus.equals(OrderLine.HOLD)){
|
| this.lineStatus = lineStatus;
| }
| }
| public LineQuantity getQuantity() {
| return quantity;
| }
| public void setQuantity(LineQuantity quantity) {
| this.quantity = quantity;
| }
| public PriceCost getPriceCost() {
| return priceCost;
| }
| public void setPriceCost(PriceCost priceCost) {
| this.priceCost = priceCost;
| }
| public Calendar getRequiredDate() {
| return requiredDate;
| }
| public void setRequiredDate(Calendar requiredDate) {
| this.requiredDate = requiredDate;
| }
| //</editor-fold>
| //<editor-fold defaultstate="collapsed" desc="Method Overides">
| @Override
| public int hashCode() {
| int hash = 0;
| hash += (this.getId() != null ? this.getId().hashCode() : 0);
| return hash;
| }
| @Override
| public boolean equals(Object object) {
| // TODO: Warning - this method won't work in the case the id fields are not set
| if (!(object instanceof OrderLine)) {
| return false;
| }
| OrderLine other = (OrderLine)object;
| if (this.getId() != other.getId() && (this.getId() == null || !this.getId().equals(other.getId()))) return false;
| return true;
| }
| @Override
| public String toString() {
| return "beltmasta.ejb.persistance.OrderLine[id=" + getId() + "]";
| }
| //</editor-fold>
| //<editor-fold defaultstate="collapsed" desc="Relationships">
| public Belt getBelt() {
| return belt;
| }
| public void setBelt(Belt belt) {
| this.belt = belt;
| }
| public Collection<SlabAssignment> getSlabAssignments() {
| return slabAssignments;
| }
| public void setSlabAssignments(Collection<SlabAssignment> slabAssignments) {
| this.slabAssignments = slabAssignments;
| }
| public void addSlabAssignment(SlabAssignment assignment) {
| int open = quantity.getOpen();
| int assign = assignment.getAssignedQuantity();
| if(assign <= open) {
| quantity.setProcess(quantity.getProcess()+assign);
| assignment.setOrderLine(this);
| slabAssignments.add(assignment);
| }
| }
| public Order getParentOrder() {
| return parentOrder;
| }
| public void setParentOrder(Order parentOrder) {
| this.parentOrder = parentOrder;
| }
| //</editor-fold>
| //<editor-fold defaultstate="collapsed" desc="Logic Methods">
| public double getTotalOrderPrice() {
| return (double)(priceCost.getPrice() * quantity.getOrder());
| }
| public double getTotalOrderCost() {
| return (double)(priceCost.getCost() * quantity.getOrder());
| }
| public double getTotalOpenPrice() {
| return (double)(priceCost.getPrice() * quantity.getOpen());
| }
| public double getTotalOpenCost() {
| return (double)(priceCost.getCost() * quantity.getOpen());
| }
| //</editor-fold>
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103395#4103395
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103395
18 years, 8 months
[JBoss Tools (users)] - Re: JBoss Tools Documentation
by max.andersen@jboss.com
"bdlink" wrote : After reading from Max (above) that we are to use Dali for persistence with JBoss tools
I did not say you have to - I just say it was an option.
We don't enable Dali by default because there are issues with Dali's default behavior (e.g. not knowing what the right default schema on dbs)
anonymous wrote :
| I tried using JPA with todays Jboss tools nightly build, after creating a seam-web project (with Seam 2). As near as I can figure, JPA only works in a JPA project. It does not appear to work with a Seam project with JPA aspect added (in the JPA structure window the message "Structure is not available for the current selection" when selecting a class which is to be bound to a database table). The Dali tutorial works but requires a JPA project.
|
Yes - so you need to enable the JPA facet. Can be done at creation time in the wizard or right click on the project and add the facet under the facet preferences.
anonymous wrote :
| The last messages sound like we should be using hibernate directly for generating Entities from DB tables.
|
I don't understand ? Just use Seam Generate Entities...(which will setup the proper Hibernate tools setup)
anonymous wrote :
| Using a seam entity does not seem to do anything useful, because the associated pages get out of synch when you edit the entity properties.
|
Yes - welcome to the land of codegeneration...
anonymous wrote :
| Perhaps more useful would be generating the other artifacts (Home, List, and pages) after the Entity has been generated.
|
So use Seam Generate Entities Wizard, but select "Use existing entities" instead of the "Reverse engineer from database"
anonymous wrote :
| Using seam-gen does not seem to work well, because it is all database tables or nothing, and gets the relationships wrong (not enough info in database schema to determine correct multiplicities and direction).
|
Yes - depending on what things you want to configure you can decide to use a .reveng.xml file to control these things very precise.
Over time we will make this more easily available. See Hibernate tools for the docs about these things.
anonymous wrote :
| After correcting the Entities you have to track down corrections in the other artifacts, since refactoring does not know about the dependencies.
|
try generating from the enttiies instead...
anonymous wrote :
| I noticed that the example JBoss tools documentation does not yet get past the front end to generating the entities.
|
Which example exactly ?
anonymous wrote :
| I am assuming/hoping that my confusion is simply due to a lack of documentation which will eventually be answered (or perhaps features which are not there but will be for GA), but I am still trying to figure the best way to do a simple application with a database that has multiple tables, with relationships.
Use Seam Generate Entities - but it is only something that generates the *basis* of an app.
anonymous wrote :
| I am trying to use JSF/Facelets/RichFaces/Seam2/EJB3/JAS4.2.2.
|
this is what the seam-gen/Wizards are targeted at.
anonymous wrote :
| Pointers to an end-to-end project would be useful (something more than a one-table CRUD example). If seam is the main focus of JBoss tools/RHDS, perhaps the examples in the Seam tutorial could be redone using these tools.
|
I don't recall any multi table examples in seam tutorial ? link ?
anonymous wrote :
| When JBoss Tools/RHDS really gets it together, it looks like it will be preferable to the NetBeans model which has the same architectural constraints that Sun Studio Creator had (each page has a backing bean that everything gets dumped into, etc.)
Yes - that is definitly not the way our tooling works - we belive in less constraints (but that also put some more responsiblity on to the programmer ;)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103388#4103388
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103388
18 years, 8 months
[JBoss Tools (users)] - Re: JBoss Tools Documentation
by bdlink
After reading from Max (above) that we are to use Dali for persistence with JBoss tools, I tried using JPA with todays Jboss tools nightly build, after creating a seam-web project (with Seam 2). As near as I can figure, JPA only works in a JPA project. It does not appear to work with a Seam project with JPA aspect added (in the JPA structure window the message "Structure is not available for the current selection" when selecting a class which is to be bound to a database table). The Dali tutorial works but requires a JPA project.
The last messages sound like we should be using hibernate directly for generating Entities from DB tables.
Using a seam entity does not seem to do anything useful, because the associated pages get out of synch when you edit the entity properties. Perhaps more useful would be generating the other artifacts (Home, List, and pages) after the Entity has been generated.
Using seam-gen does not seem to work well, because it is all database tables or nothing, and gets the relationships wrong (not enough info in database schema to determine correct multiplicities and direction). After correcting the Entities you have to track down corrections in the other artifacts, since refactoring does not know about the dependencies.
I noticed that the example JBoss tools documentation does not yet get past the front end to generating the entities.
I am assuming/hoping that my confusion is simply due to a lack of documentation which will eventually be answered (or perhaps features which are not there but will be for GA), but I am still trying to figure the best way to do a simple application with a database that has multiple tables, with relationships. I am trying to use JSF/Facelets/RichFaces/Seam2/EJB3/JAS4.2.2.
Pointers to an end-to-end project would be useful (something more than a one-table CRUD example). If seam is the main focus of JBoss tools/RHDS, perhaps the examples in the Seam tutorial could be redone using these tools.
When JBoss Tools/RHDS really gets it together, it looks like it will be preferable to the NetBeans model which has the same architectural constraints that Sun Studio Creator had (each page has a backing bean that everything gets dumped into, etc.)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103385#4103385
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103385
18 years, 8 months