Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何实现事务数据库EJB3.0_Java_Database_Transactions_Ejb - Fatal编程技术网

Java 如何实现事务数据库EJB3.0

Java 如何实现事务数据库EJB3.0,java,database,transactions,ejb,Java,Database,Transactions,Ejb,在CustomerTransactions实体中,我有以下字段记录客户购买的内容: @ManyToMany private List<Item> listOfItemsBought; @manytomy 私有列表项目列表; 当我仔细考虑这个领域时,它可能不起作用,因为商家可以更改商品信息(例如价格、折扣等)。因此,此字段将无法记录交易发生时客户实际购买的内容 目前,我只能想到两种方法来实现它 我将把交易细节记录到一个字符串字段中。我觉得如果我以后需要提取一些有关交易的信息,这种方

在CustomerTransactions实体中,我有以下字段记录客户购买的内容:

@ManyToMany
private List<Item> listOfItemsBought;
@manytomy
私有列表项目列表;
当我仔细考虑这个领域时,它可能不起作用,因为商家可以更改商品信息(例如价格、折扣等)。因此,此字段将无法记录交易发生时客户实际购买的内容

目前,我只能想到两种方法来实现它

  • 我将把交易细节记录到一个字符串字段中。我觉得如果我以后需要提取一些有关交易的信息,这种方式会很麻烦
  • 每当商户更改商品信息时,我不会直接更新该商品的字段。相反,我将使用所有新信息创建另一个新项目,并保持旧项目不变。我觉得这种方式更好,因为我以后可以很容易地提取有关交易的信息。然而,坏的一面是我的Item表可能包含很多行

  • 如果有人能给我一个如何解决这个问题的建议,我将不胜感激

    我会尝试第三种类似的选择

    public class Item {
        private String sku;
    
        private double currentPrice;
    }
    
    public class Customer {
        private String name;
    
        private List<Transaction> transactions;
    }
    
    public class Transaction {
        private Item item;
    
        private Customer customer;
    
        private double pricePerItem;
    
        private double quantity;
    
        private String discountCode;
    }
    
    公共类项目{
    私有字符串sku;
    私人双价;
    }
    公共类客户{
    私有字符串名称;
    私人清单交易;
    }
    公共类事务{
    私人物品;
    私人客户;
    私人双价股;
    私人双倍数量;
    私有字符串折扣码;
    }
    

    我将让您来计算JPA映射。

    我将尝试第三种类似的方法

    public class Item {
        private String sku;
    
        private double currentPrice;
    }
    
    public class Customer {
        private String name;
    
        private List<Transaction> transactions;
    }
    
    public class Transaction {
        private Item item;
    
        private Customer customer;
    
        private double pricePerItem;
    
        private double quantity;
    
        private String discountCode;
    }
    
    公共类项目{
    私有字符串sku;
    私人双价;
    }
    公共类客户{
    私有字符串名称;
    私人清单交易;
    }
    公共类事务{
    私人物品;
    私人客户;
    私人双价股;
    私人双倍数量;
    私有字符串折扣码;
    }
    

    我将让您计算JPA映射。

    谢谢您的建议!我有一种强烈的感觉:谢谢你的建议!我有一种强烈的感觉,它会很好地工作:D